



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




11-13 minutes
User Management Command in Linux with Examples
ASSIGNING THE PASSWORDS FOR THE USERS IN LINUX. The same follows with groups. The important thing is this command needs root privilege for accessing other users or groups. Only the same user process can be done without the privilege.
To add a new user you can use any two of the following User management commands.
Syntax
adduser
useradd
Syntax
passwd
To change the old password of the user that is already created use the following User management command.
Syntax
passwd The same in root will prompt you to change the root password. The other user's password can also be changed from the root.
passwd
To delete an user account, use the following User management command.
Syntax userdel -r [username]
Here, -r option is used to delete user along with the user’s home directory and mail spool.
There are two types of groups in Linux, they are
Primary group
To add a user to a Primary group, use the following user mod command as root,
Syntax
usermod -g [groupname] [username]
Here, If a user is added to a primary group,then the user gets the group id of the group to which it is added.
A user can be added to a secondary group using the following command.
Syntax
usermod -G [groupname] [username]
If the user is added to a secondary group,the user is added to the new group along with default group.
ADDING A GROUP
To add a group, run the following User management command
Syntax
groupadd [groupname]
To delete a group, use the following User management command
Syntax
groupdel [groupname]
Example
[root@linuxhelp ~]# groupdel group /etc./group File:
Syntax: [Group name]: [Group password]:[GID]:[Group members]
Example
group2: x:503:user
The 1st field indicates the name of the group The 2nd field specifies the group password The 3rd field indicates the group id The 4th field contains the members of the group
After adding the user you can change user’s information using the user mod commands
Syntax
usermod [options] [username]
For a normal file, write permission allows a user to modify and delete the file and for a directory. It allows a user to delete the directory, modify its contents like create, delete, and rename files in it, and modify the contents of files that the user can read.
The execute permission for a file allows a user to execute a file. User must also have read permission to execute a file. For a directory execute permission allows a user to access the directory and can view information about the directory.
Example
-rw------- : A file that is only accessible by its owner drwxr-xr-x : A directory that every user on the system can read and access
A hyphen (-) in the above examples indicates that the respective permission is not available for the particular class
If set UID is set for a file or a folder, the command is executed with the owner of the file or folder’s permission rather than the user who is executing the command.
Syntax Symbolic form: chmod -R u+s [filename] Numeric form: chmod -R 4755 [filename]
If Recursive -R is used, the parent directory’s permission will be applied to all its sub directories.
Example
[user2@linuxhelp ~]$ chmod -R u+s test
After the Set UID is set to a file or folder.it looks like this
[user2@linuxhelp ~]$ ll drwsrwxr-x 3 user2 user2 4096 Feb 25 13:40 test [user2@linuxhelp ~]$ cd test [user2@linuxhelp test]$ ll total 4 -rwSrw-r-- 1 user2 user2 0 Feb 25 13:40 1 -rwSrw-r-- 1 user2 user2 0 Feb 25 13:40 2 drwsrwxr-x 2 user2 user2 4096 Feb 25 13:40 new
If set GID is set for a file or a folder, a folder or a file created inside the parent directory will have the same group owner as the parent directory.
Syntax Symbolic form chmod -R g+s [filename] Numeric form chmod -R 2755 [filename]
If Recursive -R is used, the parent directory’s permission will be applied to all its sub directories. Example
[user2@linuxhelp ~]$ chmod -R g+s new [user2@linuxhelp ~]$ ll total 8 drwxrwsr-x 3 user2 user2 4096 Feb 25 13:45 new drwsrwxr-x 3 user2 user2 4096 Feb 25 13:40 test [user2@linuxhelp ~]$ cd new [user2@linuxhelp new]$ ll total 4 -rw-rwSr-- 1 user2 user2 0 Feb 25 13:44 2 drwxrwsr-x 2 user2 user2 4096 Feb 25 13:45 test
After the Set GID is set to a file or folder.it looks like this,
drwxrwsr-x 3 user2 user2 4096 Feb 25 13:45 new
If sticky bit permission is set for a folder, the files or folder created within the parent directory will also get sticky bit on it. The files or folders with sticky bit permission can be deleted only by root or by the owner of the file or folder, even other users with execute permission also can’t delete the file or folder.
Syntax Symbolic form chmod -R o+t [filename] Numeric form chmod -R 1755 [filename] If Recursive -R is used, the parent directory’s permission will be applied to all its sub directories.
Example
[user2@linuxhelp ~]$ chmod -R o+t test
To create a user account with no login, the following User management command can be used.
Syntax
useradd -s /sbin/nologin [username]
Example
[root@linuxhelp ~]# useradd -s /sbin/nologin user
Another way to add a user with no login is to edit the /etc/passwd file. In /etc/passwd file replace /bin/bash with /sbin/nologin for the user you’re going to restrict login.