New User Creation / Add new user
Create a new user in Linux
Table of Contents:
Adding new user
Changing Password
User Login
Switch User
Granting Admin Privileges
User Aliases
Reloading Aliases
Testing
Conclusion
>Adding new user:Creating new user with the name "testuser" shown as below.
# useradd testuser
> Changing Password:Creating password for newly created user ( ie., testuser )# passwd testuserChanging password for user testuser.
New UNIX password:
# set passwordRetype new UNIX password:
# confirmpasswd: all authentication tokens updated successfully.
> User Login:Login with newly created user ( ie., testuser ).
localhost login: testuser # Enter user-name .password: # Enter testuser password ( Password will not be display ) Then press Enter.
> Switch user:We can switch between users by using 'su' command. the below example is switch to root user.su - l $ su -l root # switch user to root , if we did not type any username then it will take root user by default . ie., we can login to root by using 'su - ' as well.Password: # Enter root password# # we have logged into root user. the '#' indicates that we are now using root user.
>Granting Administrative Privileges:Assigning administrative privileges to a user to execute root commands without switching to root user. ( ie., testuser )
# usermod -G wheel testuserEdit '/etc/pam.d/su' file. the file looks like as below.# vi /etc/pam.d/su#%PAM-1.0
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
#auth required pam_wheel.so use_uid
auth substack system-auth
auth include postlogin
account sufficient pam_succeed_if.so uid = 0 use_uid quiet
account include system-auth
password include system-auth
session include system-auth
session include postlogin
session optional pam_xauth.so
Un Comment the below lines from the file."auth sufficient pam_wheel.so trust use_uid"
"auth required pam_wheel.so use_uid"The file will be looks like below.# vi /etc/pam.d/su#%PAM-1.0
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth required pam_wheel.so use_uid
auth substack system-auth
auth include postlogin
account sufficient pam_succeed_if.so uid = 0 use_uid quiet
account include system-auth
password include system-auth
session include system-auth
session include postlogin
session optional pam_xauth.so
> User aliases:
Creating an alias for the root user and forwarding all root user emails another user. ( ie., testuser )
# vi /etc/aliasesuncomment the last line and enter the username as shown below.root: testuser
> Reloading aliases:
# newaliases
> Testing:Try to login to root user from testuser. in general, it should ask for the password. but testuser having root privileges so that we can login without entering any password like a root user.$ su -l root
#
> Conclusion:We have learned user creation, password creation, User login, Switching user using 'su' command, Assigning administrative privileges to a normal user in this article and tested successfully.Any questions please make a comment.Thankyou
Read the full article