Linux su CommandsThe su command allows you to run a shell as another user. Syntax: Example: Look at the above snapshot, user account is changed from sssit to jtp. su to rootYou can change the user to root when you know the root password. Syntax: su as rootThe root user can become any existing user without knowing that user's password. Otherwise, password is needed. Example: Look at the above snapshot, it is asking for password while switching from user jtp to sssit. Now let's look at the following example. Example: Look at the above snapshot, we are at user root. While switching from root to jtp it didn't ask for password and we're successfully arrived at user jtp. su - $usernameBy default, the su command maintains the same shell environment. To access the target user's shell environment use the su command with (-) followed by the target user name. Example: Look at the above snapshot, with the command "su - jtp" current shell environment is /home/jtp and user is also jtp. With the command "su jtp" current shell environment is /home/sssit and user is sssit. su -If any user name is not mentioned then by default, it will assume root as the target user. Example: Look at the above snapshot, command "su -" has assumed root as the target. Running Program As Another User / sudo CommandThe sudo command allows a user to start programs with the credentials of another user. Example: Look at the above snapshot, shell gives the above message while creating usr 'akki'. Command With sudoWith sudo command we're allowed to create new users on the system without becoming root or without knowing the root password. Example: Look at the above snapshot, user 'akki' is created with sudo command. sudo su -By default, some Linux systems like Ubuntu, don't have a password set for root user. It means you can't login as root user. To perform root like task, a user is given all sudo rights via etc/sudoers. All the users that are members of the admin group can use sudo command for performing root tasks. Syntax: Look at the above snapshot, commnd "grep admin /etc/sudoers" allows all the admin group users to gain root peivileges. By typing sudo su - a user can become root user without typing password for root. The sudo command will ask for the user's own password. Syntax: Look at the above snapshot, bash is asking for sssit password not for root password, after that we are logged in as root user.
Next TopicLinux User Management
|