Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Manage user account as root
06-11-2018, 06:15 PM (This post was last modified: 06-14-2018 03:38 PM by cchen.)
Post: #1
Manage user account as root
In this guide, we will introduce how to create user accounts, assign sudo privileges, and delete users on a CentOS 7 system.

Make sure you are logged in as root (you can use "who" ot "whoami" to check who is currently logged on to the system)

Adding Users
If you are signed in as the root user, you can create a new user by:
Code:
adduser username
If you are signed in as a non-root user who has been given sudo privileges, add "sudo" in the front:
Code:
sudo adduser username
Next, you'll need to give your user a password so that they can log in. To do so, use the passwd command:
Code:
passwd username
You will be prompted to type in the password twice to confirm it.

Granting Sudo Privileges to a User
If your new user should have the ability to execute commands with root (administrative) privileges, you will need to give the new user access to sudo.
We can do this by adding the user to the wheel group through the gpasswd command:
Code:
gpasswd -a username wheel

Managing Users with Sudo Privileges
In order to see which users are part of the wheel group, you can use the lid function with the -g flag:
Code:
sudo lid -g wheel
The output will show you the usernames and UIDs that are associated with the group. This is a good way of confirming that your previous commands were successful

usermod – Modify a user account.
example: user1@foo ]$ usermod -a -G sshusers user1 (this command adds user1 to the group sshusers.)

Deleting Users
If you have a user account that you no longer need, it's best to delete the old account.

If you want to delete the user without deleting any of their files, type this command as root:
Code:
userdel username
If you want to delete the user's home directory along with the user account itself, type this command as root:
Code:
userdel -r username

Although you can directly log in as a root user, it’s usually much safer to take on root privilege only when necessary, using the su (switch user) command:
Code:
$ su
Password:
                     root-password

there are four different command shells: csh (a.k.a. tcsh), bash (a.k.a. sh), ksh, and zsh. You can temporarily start a different shell just by typing the shell name:
$ csh
Press Ctrl-D or type exit to return to the original shell. You can permanently change your default shell using the chsh (change shell) command
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Manage user account as root - cchen - 06-11-2018 06:15 PM

Forum Jump: