Ubuntu Linux
This is a quick walk-through of various commands related to adding and removing users in linux. All examples are tested in Ubuntu 16.04
Adding user
$ sudo adduser joe
Adding user `joe' ...
Adding new group `joe' (1001) ...
Adding new user `joe' (1001) with group `joe' ...
Creating home directory `/home/joe' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for joe
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] y
We skipped all user information like full name etc.
List users
To confirm that user has been created, we can list all users:
$ cut -d ":" -f 1 /etc/passwd
Note that $ users command shows only currently logged users.
Change password
$ sudo passwd joe
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
You can also change password if logged in as 'joe':
david@main-server:~$ su - joe
Password:
joe@main-erver:~$ passwd
Changing password for joe.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Add user to a group
To add a user to a group e.g. 'sudo' (the executor of this command must be in sudo group):
$ sudo adduser joe sudo
Adding user `joe' to group `sudo' ...
Adding user joe to group sudo
Done.
Delete user
You must be logged as a user other than 'joe':
$ sudo userdel -r joe
-r is used to delete all related files created for/by 'joe'.
You may also need to kill all currently running processes of the user before deleting it:
killall -u joe
|