×


How to log into your Linux Server as a root user?

Are you trying to log in to your Linux server as the root user?

This guide will help you out.

On Linux operating systems, the root user act as a superuser. The root account has root privileges. What this means is that it can read and write any files on the system, perform operations as any user, change system configuration, install and remove software, and upgrade the operating system and/or firmware. In essence, it can do pretty much anything on the system.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Software Installation tasks on their server.
In this context, we shall look into how to run commands as root user using nonuser, su, and sudo utilities.

More about Root user on Linux?

Root user is the conventional name of the user who has all rights or permissions on the system. The root user can do many things an ordinary user cannot, such as changing the ownership of files, mounting disk, formatting & restating new file system, starting/stopping services, and binding to ports numbered below 1024 and any other tasks.
Basically, it is not a good practice for anyone to use root as their normal user account, because of security risks. Therefore, you use a normal user account instead. You need to use the su or sudo command to switch to root user account.

Here we will look into some commands which root user enjoys.

1. su command.

The su command is use to change user ID or become super-user during a login session i.e. it allows you to become a super user or substitute user, spoof user, set user or switch user.

Note: su only works if you know the target or root user's password.

What is the su command syntax?

The syntax is:

su - {user-name}

If used without a user-name, su defaults to becoming the super user. The user will be prompted for a password accordingly.
To log in as root user type the following command (you need to supply root user account password when prompted):

$ su -

You will get an output such as;

Password: *******
# 

Once logged in, your prompt should change from $ to #. To log in as another user say linuxapt, run the following command (you need to supply linuxapt user account password when prompted):

$ su - linuxapt

You will get an output such as this;

Password:

2. How to establish Remote root login over the ssh session?

Now with an ssh client tool such as putty, you can run the following command;

$ ssh root@server.ip-address-here
$ ssh root@server1.linuxapt.com

In some cases, the remote root login over ssh session is disabled in most cases for security reasons.
Start by logging in as a normal user and then switch to root account using the su command as shown below;
## login as a normal user ##

ssh user1@server1.linuxapt.com

 ## now switch to root account ##

su -

3. More about su command and log files?

The su command logs its usage in a system log file. This is useful to find out su login information.
If you are RHEL / CentOS / Fedora Linux user type the following as root to see the contents of "/var/log/secure", execute the command:

tail -f /var/log/secure

For Debian / Ubuntu Linux user, execute:

tail -f /var/log/auth.log

4. More about sudo command?

The sudo is a program for Linux operating systems that allows users to run programs with the security privileges of another user, normally the superuser (root). By default, sudo will prompt for a user password but it may be configured to require the root password or no password at all. Ubuntu Linux and many other Operating system uses sudo command for many administrative tasks.
sudo executes a command as another user but follows a set of rules about which users can execute which commands as which other users. This is configured in a filed named /etc/sudoers. Unlike su, sudo authenticates users against their own password rather than that of the target user. See how to configure and use sudo tool under Linux operating system.


For instance, to login as root under Linux, execute the command:

$ sudo -s

Then your will be prompted to enter a password. Once you enter the password, you will be logged in as the root and you will be able to enjoy sudo privileges.


5. How to work with Sudo and log file?

The sudo log can be viewed by issuing the following command as root user:

## Generic file for Unix/Linux ##

tail -f /var/log/messages

## Debian/Ubuntu ##

tail -f /var/log/auth.log

## RHEL/CentOS/SL/Fedora Linux ##

tail -f /var/log/auth.log


[Need urgent support to install any Software on your CentOS Server? Our Server Administrator will help you today.]


Conclusion

This article will guide you on how to run commands as root user using nonuser, su, and sudo utilities.