Day 37 - Users and Permissions in Linux

This is the sixth post in the Linux series and it will be about Users and Permissions in Linux. But first of all what are users and permissions in Linux?

What are Users in Linux?

Linux OS provides the ability of multitasking and management of task by more than one user at a time. It was designed to work with multiple users working at the same System at the same time. Other OS like Windows does not allows more than one user to work at the same time. So in order to make it work properly and for security reasons Users are created in the Linux with limited privillages to perform multitasking.

Each user has a set of permissions. What things that they can access in the system is defined in the permissions that are allowed to them by the admin/root user. An admin user has all the access permissions on the system and they can do anything they want with the system like deleting everything in the system. So for security purposes it is necessary to create users with limited access that they need to perform the work that is required of them and not access anything else.

Many System Admins create a user for themselves with limited permissions to not accidently damage any file that require root access. Now to permissions.

What are permissions?

Permissions or access rights are measures that control the ability of the user to create, modify, execute or navigate the file/directories in the file system. Basic permissions are follwoing.

  • Create - the permission for a user to create files.
  • Modify - the permission for a user to make a change or delete a file.
  • Execute - the permission to execute any files they want.
  • Navigate - the permission to naveigate to any directory of choice and views contents in them.

Creaing User in Linux

To create a new user in Linux useradd command is used. Type useradd followed by the name of the user and hit enter and it will create the user.

root@User:/$ useradd new-user

All the users that are created or were created by the system are stored in /etc/passwd. Now run the cat command with /etc/passwd and it will print out all the users with the newly created user at the last.

root@User:/$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
...
...
...
new-user:x:1000:1000::/home/new-user:/bin/sh

You may need root access if you are not logged in as the admin to create a user. useradd command also accepts some options to add to the new user like adding expiry date for the user of creating home directory for the user to login to.

There is also another command that is easier for people that are new to Linux to create users. It is adduser command. It create the defualt home dir for other necessary things for a new user that you have to do manually when creating a user with useradd command. It works same as the first command.

root@User:/$ adduser another-new-user
Adding user `another-new-user' ...
Adding new group `another-new-user' (1001) ...
Adding new user `another-new-user' (1001) with group `another-new-user' ...
Creating home directory `/home/another-new-user' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for another-new-user
Enter the new value, or press ENTER for the default
        Full Name []: New User
        Room Number []: New User Room Number
        Work Phone []: New User Work Number
        Home Phone []: New User Phone Number
        Other []: Others
Is the information correct? [Y/n] Y

You see that it will ask some questions about the newly created user and assigns it to a new group by itself. All these things you have to do manually if created with useradd command.

Deleting a User

To delete a user first you need to have admin access and them type deluser command with users name as the arugment.

root@User:/$ deluser new-user

Setting password for the newuser

To setup a password for the newuser type passwd command with users name as the argument and hit enter and it will ask you for the password. When typing password it will not show how many words are typed as they do in the browser and so be careful when typing the password.

root@User:/$ passwd new-user
New password:
Retype new password:
passwd: password updated successfully
root@User:/$

Thats it for today and next will be about groups and adding permissions to the users and assigning users to the group.


zainscizainsci