Sponsored Link

Initial Settings : Add User Accounts2021/07/16

To add user accounts on Rocky Linux Server, Configure like follows.
[1] For example, Add [rocky] user.
[root@localhost ~]#
useradd rocky

[root@localhost ~]#
passwd rocky

Changing password for user rocky.
New UNIX password:              # input any password you'd like to set
Retype new UNIX password:       # confirm
passwd: all authentication tokens updated successfully.
[2] If you'd like to switch to root account from a user added above, use [su] command to do so.
localhost login:  rocky         # login username
password:                       # input user password
[rocky@localhost ~]$
su -
# switch to root

Password:                       # input root password
[root@localhost ~]#             # just switched to root
[3] If you'd like to limit users to run [su] command, configure like follows.
On the example below, only users in [wheel] group can run [su] command.
[root@localhost ~]#
usermod -aG wheel rocky

[root@localhost ~]#
vi /etc/pam.d/su
auth            required
auth            sufficient
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
# uncomment the following line
auth            required use_uid
auth            substack        system-auth
auth            include         postlogin
account         sufficient uid = 0 use_uid quiet
account         include         system-auth
password        include         system-auth
session         include         system-auth
session         include         postlogin
session         optional

# verify settings with a user who is not in allowed group

[redhat@localhost ~]$
su -

su: Permission denied     # denied normally
[4] If you'd like to remove a user accounts, Set like follows.
# remove a user [rocky] (only removed user account)

[root@localhost ~]#
userdel rocky
# remove a user [rocky] (removed user account and his home directory both)

[root@localhost ~]#
userdel -r rocky
Matched Content