Being root in linux

5 Best Ways to Become root user or Superuser in Linux (RHEL / CentOS / Ubuntu)

5 Best Ways to Become root user or Superuser in Linux (RHEL / CentOS / Ubuntu) 1

In this tutorial, I will take you through 5 Best ways through which you can become root user or superuser in Linux. If you want to run any privilege command in your Linux Based Servers then you need to have root or superuser access. There are many commands on Linux System which cannot run through any other user apart from root or superuser.

So you always need to switch or change to root user in case you want to run any privileged commands. This is one of the common scenario every Linux Professionals face in their day to day work. root user is like admin user which has complete control of the System. Here we will look into different ways using which you can switch or change your user to root or superuser to run any of the privileged commands.

5 Best Ways to Become root user or Superuser in Linux (RHEL / CentOS / Ubuntu) 2

Ways to Become root user or Superuser in Linux

Method 1: Use ‘sudo -i’ to become root user or superuser in Linux

If you are currently logged in as non-root user then you can use sudo -i command to login as root user as shown below. If the current user does not have sudo access then it will ask for the password as you can see in the below output but if the current user has sudo access then it won’t ask for the password.

On ubuntu based systems by default root user will be blocked so you have to first login as non-root user and then use sudo -i to login as root user. You can check Step by Step: How to Add User to Sudoers to provide sudo access to the User.

test@test-localhost:~$ sudo -i [sudo] password for test: root@test-localhost:~#

-i : Run the shell specified by the target user’s password database entry as a login shell. More on sudo command Man Page.

Method 2: Use ‘sudo -s’ to become root user or superuser in Linux

If you are currently logged in as non-root user then you can use sudo -s command to login as root user as shown below. This method are generally used in Linux based Cloud Instances where you need to first login as different user and then switch to root user to run any privileged commands as by default root user will be blocked.

test@test-localhost:~$ sudo -s root@test-localhost:/home/test#

-s : Run the shell specified by the SHELL environment variable if it is set or the shell specified by the invoking user’s password database entry. More on sudo command Man Page.

Читайте также:  Ввод пароля скрипт linux

Method 3: Use ‘sudo su -‘ to become root user or superuser in Linux

You can also use su(switch user) command with sudo to switch your user. If you are currently logged in as non-root user then you can use sudo su — command to login as root user as specified below. When you see $ on the output prompt then it means current logged in user is non privileged user and when you see # on the output prompt then it means you are currently logged in as root user.

test@test-localhost:~$ sudo su - root@test-localhost:~#

Method 4: Use ‘su — root’ to become root user or superuser in Linux

Another way through which you can switch your user to root user is by using su — root command as shown below. By now you should be able to differentiate between sudo and su command. sudo is basically used to run privileged command and su is to switch user. Both of the tools can be used effectively to become root user or superuser on Linux based Systems.

[centos@localhost ~]$ su - root Password: Last login: Sun Oct 11 12:37:59 EDT 2020 from 192.168.0.101 on pts/0

Method 5: Use ‘su -‘ to become root user or superuser in Linux

If you do not mention the root user with su command and use only su — command then also by default it will switch to root user or superuser as shown below.

[centos@localhost ~]$ su - Password: Last login: Sun Oct 11 12:38:42 EDT 2020 on pts/0

Popular Recommendations:-

Источник

How to become root in Linux

root in linux

Computer Hope

On every Linux system, the root account is a special user with administrative rights. Logging in as root (or executing commands with root privileges) is necessary for many tasks. If you need to perform tasks as the root user, make sure you fully understand the commands you are running, and what consequences they have. A single careless or malformed command, run as root, can make the entire operating system unusable. Do your research, and always double-check every command before pressing Enter .

Logging in as root

The root account is similar to any other account in that it has a username («root») and a password. If you know root’s password, you can use it to log into the root account from the command line.

There is a special command named su (for «super user,» or «switch user») that lets you run commands as the root account temporarily. From the command line, type:

Читайте также:  Сервер управления компьютерами linux

Enter the password once prompted for the password. If successful, you are switched to the root user and can run commands with full system privileges.

Be careful while logged in as root. It is easy to forget you’re currently the root user, and you might inadvertently run a command thinking you are only a mere mortal. One way to remind yourself if you are root or not is to check your command prompt. Many systems end their command prompt with a dollar sign («$«) if you’re logged in as a normal user and a pound sign («#«) if you’re root.

Or, you can use the whoami command to determine the account you are using.

When finished with your administrative tasks, you can run the exit or logout command to return to your standard user account.

When logging in as root, it is often useful to use a single dash after the su command, like this:

This command simulates a complete root login. It executes all of the root user’s shell initialization scripts and sets all environment variables as if the root logged in to a fresh shell session. Depending on what task you need to perform, and how root is configured, this form of the su command might be optimal for you.

Running commands as root without the root password

It is possible, and often preferable, to run commands as root without logging into the root account using the sudo command, which stands for «superuser do.» If you prefix a command with sudo, you are prompted for your password (not the root password), and your name is checked against a special file called sudoers. If your account is listed there, your command runs with root privileges.

Using sudo makes it difficult to forget you’re root since you’re not logged in to the root account, and are never going to forget to log out. Also, typing sudo every time you run a potentially destructive command reminds you to be extra careful and double check yourself.

If you need to add a user to the sudoers list, use the visudo command that requires root privileges to run, and lets you safely edit the sensitive sudoers file.

Источник

How Do I Become a Root User in Linux

The root is the super-user account on Linux-based operating systems. The root user has all the rights that are necessary to perform administrative tasks or access some files, execute privileged commands, and much more. The root user is also referred to as a superuser or root.

In Linux, you can run privileged commands using the sudo keyword. However, sometimes it becomes a tedious act when you are doing administrative tasks and each command requires root privileges. To get rid of such a situation, become a root user and then execute commands.

This article provides various possibilities to become a root user on Linux.

How do I become a root user on Linux

As discussed earlier the root user has the necessary privileges to execute and perform various tasks on Linux-based systems. This section demonstrates Linux commands that can be used to become a root user on Linux.

Читайте также:  Линукс снс не работает

How to use the sudo command to become a root user

The sudo command allows a normal user to perform the tasks that a superuser can do. Here, we provide the possible usages of the sudo command to become a root user.

Using the “sudo su –”

The `su` refers to switching the user and if the username is not provided, it will switch you to a root user, and the command provided below assists in this regard.

Graphical user interface Description automatically generated with low confidence

After successful authentication, it is noted that we are now switched to a root user.

Using the “sudo su”

The command written below will change the privileges to the root user.

A screenshot of a computer Description automatically generated with medium confidence

Using the “sudo -i”

The command provided below will change the privileges to a root user.

Graphical user interface Description automatically generated with low confidence

The output shows that the dollar sign($) has been replaced by the pound key(#) which also directs that you are currently logged in using the root privileges.

Using “sudo -s”

The “-s” parameter enables the user to run the shell with a specific user. And if the username is not specified then the root (default) is considered.

Text Description automatically generated

How to use su command to become a root user

The su command allows you to switch the user to someone else by providing its username. However, if the name is not specified, the su command would allow you to execute the commands with root privileges.

There are various parameters that would allow you to become a root user.

Using “su –”

A screenshot of a computer Description automatically generated with medium confidence

Using “su -l”

A screenshot of a computer Description automatically generated with medium confidence

Using “–login”

A screenshot of a computer Description automatically generated with medium confidence

It is observed from the above outputs that you are switched to the root user and can now perform the privileged tasks.

During the authentication of su command, you have to put the root password.

Note: In case you are unable to execute the above commands, you must set the password for root by using the following command.

Text Description automatically generated

Bonus Tip

Once you are logged in as a root user, it is recommended to check whether you are working with root privileges or not. To do so, the $LOGNAME variable would help, as the $LOGNAME contains the user you are currently logged in as.

For instance, we have tried to switch to the root user using the “su” command, and let’s check the logged-in user with the help of the following command.

Graphical user interface Description automatically generated with low confidence

The output shows that you are not logged in using the root privileges.

Conclusion

The root user is the ultimate boss of a Linux system, it can perform any task without any hurdle. This guide intends to explore the possible commands or ways to become a root user on Linux so that the frequent authentication hurdle can be avoided. Lastly, it is concluded that the sudo and su keywords are the main stakeholder to become a root user on Linux-based machines. The sudo requires the password of the currently logged-in user whereas the su requires the password of the target user.

Источник

Оцените статью
Adblock
detector