When you install a new Linux system, most of the times you are only given the root
account by default. While the root
user gives you a lot of power and flexibility, it is also dangerous to regularly use an account which can have to much "power" due to it's privileges.
Be aware - a root
user is more vulnerable to security exploits, since any commands executed under that account can affect the system’s entire filesystem.
It is a good practice to add an additional, unprivileged user to do common tasks. There might be times when you will have to create additional accounts for any other users that need access to the system. Each user should have it's own account so that their activities can be monitored and managed. The non-root users can still acquire administrative privileges, when needed, through a mechanism called sudo.
Log in to your system as the root
user:
localhost$ ssh root@<remote_ip>
Use the adduser
command to add a new user to your system:
# adduser newuser
Use the passwd
command to update the new user’s password:
# passwd newuser
Set and confirm the new user’s password at the prompt. It is best to set a strong password:
Changing password for user newuser. New password: Retype new password: passwd: all authentication tokens updated successfully.
Use the usermod
command to add the user to the wheel
group:
# usermod -aG wheel newuser
On CentOS Linux, members of the wheel group have sudo privileges by default.
Test the sudo
access for your new user account.
Using the su
command, switch to the new user account:
# su - newuser
Once switched to the new user, verify that you can use sudo
to run a command with superuser privileges. For example, try to list the contents of the /root
directory, which is normally only accessible to the root
user:
newuser$ sudo ls -la /root
The first time you use sudo
in a user session, you will be prompted for the password of that user's account. You have to enter the password to proceed:
[sudo] password for newuser:
If the user is in the proper group and you entered the password correctly, the command that you issued with sudo
will run with root privileges.