Linux Command Line Basics: Part 3

In today’s post we will learn how to manage users and groups. For those of you who are new to this site, do read the first part and the second part of the Linux command line basics before continuing. Let’s get started-

1. adduser – Add user. Syntax is ‘sudo adduser <user name>’. We need to use ‘sudo’ as root privileges are required to run this command. A root user can run the command without ‘sudo’. To add a new user named ‘mint1’, issue the following command in the terminal:

sudo adduser mint1

Enter the user password when prompted. A new user called ‘mint1’ will be created. A home directory will be created for the new user in ‘/home’ location. The name of new user’s home directory will be same as his user name. [Note that the default structure of the home directory is defined in ‘/etc/skel’ (skel=skeleton). Every time a home directory is to be created for a new user, files are copied from ‘/etc/skel’]. The system will now ask you to create a password for this new user. Type the password and re-type it when prompted. Ask the user to change this password to a desired one by using ‘passwd’ command when the user logs in for the first time. You can also enter the full name and contact details of the new user when prompted. Type ‘y’ to confirm the information and hit enter.

In similar manner, to add a new user named ‘mint2’, issue the following command in the terminal:

sudo adduser mint2

Note that two new home directories have been created for users ‘mint1’ and ‘mint2’ in ‘/home’ location.

2. deluser – Delete user. Syntax is ‘sudo deluser <user name>’. We need to use ‘sudo’ as root privileges are required to run this command. A root user can run the command without ‘sudo’. To delete the user ‘mint1’ issue the following command at the terminal:

sudo deluser mint1

Note that the above command does not delete user’s home directory. It is still present in ‘/home’ location.

If you want to delete a user as well as his home directory, use the option ‘-remove-home’. In order to delete user ‘mint2’ as well as his home directory issue the following command at the terminal:

sudo deluser mint2 -remove-home

Note that the user’s directory has been deleted from the ‘/home’ location.

3. addgroup – Add group. Syntax is ‘sudo addgroup <group name>‘. We need to use ‘sudo’ as root privileges are required to run this command. A root user can run the command without ‘sudo’. To add a group called ‘team1’, issue the following command at the terminal:

sudo addgroup team1

To add a group called ‘team2’, issue the following command at the terminal:

sudo addgroup team2

Now, click on ‘Menu>Administration>Users and Groups’.

Click on ‘Manage Groups’.

Notice that groups ‘team1’ and ‘team2’ have been added. Select ‘team1’ and click ‘Properties’.

You can view the list of users who are members of this group. Click ‘OK’ to close the window.

You can also select a user and click ‘Advanced Settings’.

Enter user password when promopted and click ‘Authenticate’.

In the ‘Change Advanced User Settings’ window, you can modify user’s main group, if required.

4. delgroup – Delete group. Syntax is ‘sudo delgroup <group name>’. We need to use ‘sudo’ as root privileges are required to run this command. A root user can run the command without ‘sudo’. In order to delete groups ‘team1’ and ‘team2’, issue the following commands at the terminal:

sudo delgroup team1

sudo delgroup team2

5. passwd – Change user password. Syntax is ‘passwd <user name>’. You can change the password for the user whose name has been entered.

You need to enter your current password, new password and then re-type the new password.

6. who – Shows list of logged on users. To view the users which are logged on, issue the following command at the terminal:

who

Note that the users ‘root’ and ‘ihaveapc’ are logged in the system(entries 1 and 2). Entry 3 (pts/0) denotes the pseudo terminal slave session of user ‘ihaveapc’ (as we have opened a terminal in the GUI after logging in to the Gnome desktop, that session becomes the slave session of our current session in the GUI).

That’s it for today. We’ll stop here for the sake of the length of the post. In next article we’ll see how to add users to groups via command line and how to change file/folder permissions via command line.