Creating a new user on a Linux workstation with the shell.

Posted: March 30, 2012. At: 10:24 PM. This was 5 years ago. Post ID: 3031

Creating a new user with the Linux command-line is very easy, the command-line adduser command is easier to use than the useradd command and automates a lot of the steps involved in creating a new user and their home directory. The sequence shown below is the simple task of creating a new user and shows how easy it is using BASH. This command will copy files from the /etc/skel folder, giving the user the ~/.bashrc and ~/.bash_profile configuration files in their home directory.

-22:02:12-- gordon@deusexmachina [~]$ sudo adduser mint
Adding user `mint' ...
Adding new group `mint' (1002) ...
Adding new user `mint' (1002) with group `mint' ...
Creating home directory `/home/mint' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for mint
Enter the new value, or press ENTER for the default
	Full Name []: John Smith
	Room Number []: 13
	Work Phone []: 789945678
	Home Phone []:
	Other []:
Is the information correct? [Y/n] y
-22:02:57-- gordon@deusexmachina [~]$

The userdel command is used to remove a user from the system. This procedure is shown below.

-22:17:56-- gordon@deusexmachina [~]$ sudo userdel -r mint

The -r parameter will recursively erase the home folder of the user and their files. Similar to using rm -rf /home/mint and erasing their folder. But the userdel -r mint command is safer than typing rm -rf --no-preserve-root willy nilly as the root user. That is dangerous. Sure, rm -rf /files would work, but better to use something like this instead.

jason@jason-desktop:~/Desktop$ rm -rvf stuff/
removed directory 'stuff/stuff2'
removed directory 'stuff/stuff'
removed directory 'stuff/stuff3'
removed directory 'stuff/'

That will delete the directory and all subdirectories in a safer way. The rmdir --ignore-fail-on-non-empty stuff/ command did not work for me.

No comments have been made. Use this form to start the conversation :)

Leave a Reply