Linux Users
The concept of permissions and user rights in Linux may sound too confusing but once you have enough control on the topic, you will definitely enjoy using it.
In this article, we are going to teach you how to manage users and their rights with examples. .
Introduction
Just like any other Operating System, Linux/Unix operating systems also gives you the awesome feature of multitasking but there is an interesting plus, i.e. in linux, you have the power to have multiple users simultaneously.
From the very start, Linux was designed with the ability to allow multiple user access to the system simultaneously. This is where the developers felt the need of protecting users and their data from each other so they can work together. The goal was achieved by implementing the user groups and the rights.
There are 3 basic user permissions as explained:
- Read – it gives you the read only option. The user can view the content of the folder / file but they cannot modify anything.
- Write – With the write permission on a file / folder, the users can modify the content. The users can read them, edit them and can delete them.
- Execute – any file / folder having the executable permission allows the users to run the file, program or script.
How to check file permissions:
Viewing the permissions against any file is very easy. A user can view the permissions for any file or directory by issuing the following command:
ls -l <directory/file>.
You should expect the following output against the above command:
-rw-r–r– 1 root root 1031 Nov 18 09:22 /etc/passwd
-rw-r–r– show the access rights and they can be explained as under:
- The very first dash (-) shows the file type.
(d = directory, s = special file, – = regular file).
- The following three characters (rw-) shows the owner’s permission.
- The next three characters (r–) are the permissions for the members of the same group as the file owner
- The last three characters (r–) show the permissions for all other users
How to assign rights
The following sections will go over the commands needed to create, delete, and modify user accounts. Groups will be covered, as well as commands for creating and deleting directories. You will be provided with the commands and descriptions needed for working with users, groups, and directories.
Creating and Deleting User Accounts
We can use useradd command to create any standard user.
useradd <name>
You can get the maximum out of the useradd command using the following attributes:
Attribute | Description | Syntax |
-d <home_dir> | home_dir will be used as the value for the user’s login directory | useradd <name> -d /home/<user’s home> |
-e <date> | Sets a date for expiring the account will expire | user add <name>** -e <YYYY-MM-DD> |
-f <inactive> | Sets number of days before the account expires due to no activity | useradd <name> -f <0 or -1> |
-s <shell> | sets the default shell type | useradd <name> -s /bin/<shell> |
Once you have a user created, you would be required to set him a password using the following command:
passwd <username>
Users can change their passwords using the following set of commands
$ passwd
Changing password for lmartin.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
To remove a user account in Linux, enter the following command:
userdel <name>
The above command will delete the user accounts only and if you want to delete the files and home directory etc associated with any user along with his user name, execute the following command
userdel -r <name>
there is no harm in practicing Linux on a virtual machine before start working in a live environment. It may sound boring or difficult but once you get to know Linux, there is no way back to the windows.