Linux log in as sudo

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.

Источник

How to become Root user in Ubuntu Command Line using su and sudo

Using su and sudo on Ubuntu

Before starting with how to become a root user in order to perform sensitive Ubuntu operations, it is important to have some understanding of the significance of a root user in Linux. The latest versions of Ubuntu, by default, do not come with a root user with a specially encrypted password; it has hence created a functionality by the name of “sudo” which you can use to perform various administrative operations. You can either temporarily become root user or you need to provide a password with the sudo command that helps in keeping accountability for all actions of the user as an administrator. By default, the first user created when you install Ubuntu is given the sudo rights. Ubuntu gives it complete root privileges and it is added to the list of sudoers in the /etc/sudoers file. It is important to note that you need to be an authorized sudoer to perform all the root user operations described in this article.

About the Article

In this article, we will explain how to become a root user in the Ubuntu command line. This will help you in performing all the software installation, removal, customization, and also system configuration operations. We have run the commands and procedures mentioned in this article on a Ubuntu 20.04 LTS system. We will be using the Ubuntu command line, the Terminal, in order explain how to become and also how to change the password for root user. Therefore, you need to open the Terminal application either through the system Dash or the Ctrl+Alt+T shortcut.

How to become root?

Open your Ubuntu Terminal and enter the following command:

This command will ask the system to log you in as a superuser.

su - command

The system will ask you the password for root. Enter the password and hit Enter.

Читайте также:  Arch linux best linux distro

Ideally, you now will be able to see the “#” sign in front of your command prompt. This would mean that you are now logged in as root.

In case you get the following authentication failure message when you enter the password for root, it means that the root account is blocked at the moment.

Su command - authentication failure

You can read later in the article about how to lock/unlock the root account.

To become root user from an unprivileged (normal user account) account when there is no root password set, use this command:

Enter the password of your Ubuntu user when requested. Only Ubuntu users that are members of the sudo group are able to become root user like this. The user that is created during Ubuntu installation is a member of the sudo group by default.

Now that you are logged in as root, you can perform all the administrative operations on Ubuntu.

Let us explain this with an example.

The file adduser.conf located in /etc/ needs root privileges for you to make any changes to it. When we open it as a normal user, you will be able to see the following lines at the end of the file:

“File ‘adduser.conf; is unwritable’

Editing /etc/adduser.conf

The system file is mentioned as unwritable because an unauthorized user can not make any changes to its configurations.

You can only edit it if you are logged in as root or if you are using the sudo command to temporarily avail root privileges.

Since we are now logged in as root, we will be able to see the file in the following manner:

Content of /etc/adduser.conf file

We can make any changes to the file and save the changes by hitting Ctrl+X.

Note: It is very important to stay careful while making any sensitive changes to your system files while logged in as root. Any undue change to the system files can mess up with your entire system settings.

You can exit the root command prompt and become a normal user again by using the exit command as follows:

Get Temporary root access through the sudo command

Instead of logging in as a root in the command line and getting on to the # (root user) command prompt, you can use the sudo command with your other commands to temporarily become root.

For example, we can open the same adduser.conf file that we mentioned before in an editable format by availing the root rights as follows:

This is especially useful because any authorized user(the one added in the sudoers list) can enter their own password and temporarily gain root access for running a few commands. Another benefit of using this command is that you can perform tasks that require root privileges even when the root account is in a blocked state.

Unlock/lock root account

When you get the following message when logging in as root, it is most probably because the root account is locked. Most Ubuntu systems have this account locked by default.

Locked root account

You can, however, unlock it by entering the following command as sudo:

Ublock root account

The system will ask you to enter a new UNIX password twice. After that, it will update the root password and the account will be unlocked.

Читайте также:  Deploy linux kali linux

After you are done with performing your root operations, you can lock the root account again by entering the following command:

Lock the root account

How to change the root password (An alternative approach)?

Apart from the method we just described above to change the root password, you can use the following alternative method:

Only a root user can change his/her own password. Therefore you need to login as root first. Enter the following command to do so:

The system will prompt you to enter the current sudo password. Please enter the password and hit Enter.

sudo -i command

Now that you are logged in as root, you can change the passwd for the current (root) user by using the passwd command as follows:

Run passwd command as root user

After working along with this article, you are now capable of becoming root on your Ubuntu command line. You are now free to perform all the operations that only an extremely privileged user is entitled to perform. But be very careful as Uncle Ben would say, With great power comes great responsibility!

About This Site

Vitux.com aims to become a Linux compendium with lots of unique and up to date tutorials.

Latest Tutorials

Источник

Как стать суперпользователем в Linux

В создании этой статьи участвовала наша опытная команда редакторов и исследователей, которые проверили ее на точность и полноту.

Команда контент-менеджеров wikiHow тщательно следит за работой редакторов, чтобы гарантировать соответствие каждой статьи нашим высоким стандартам качества.

Количество просмотров этой статьи: 105 805.

Учетная запись суперпользователя в Linux предоставляет полный доступ к системе. Права суперпользователя (администратора) необходимы для выполнения команд в Linux, особенно тех команд, которые затрагивают системные файлы. Так как аккаунт суперпользователя имеет неограниченный доступ к системным файлам, рекомендуется получать права суперпользователя только при необходимости, а не входить в систему в качестве администратора. Это поможет предотвратить случайное повреждение важных системных файлов.

Получение прав суперпользователя через терминал

Изображение с названием Become Root in Linux Step 1

Изображение с названием Become Root in Linux Step 2

Введите . su — и нажмите ↵ Enter . С помощью этой команды можно войти в систему в качестве суперпользователя. Используйте указанную команду для входа в систему в качестве любого пользователя, но если команда не содержит имени пользователя, вы войдете в систему как администратор. [1] X Источник информации

Изображение с названием Become Root in Linux Step 3

  • Если появилось сообщение об ошибке аутентификации (authentication error), скорее всего, учетная запись суперпользователя заблокирована. Чтобы узнать, как разблокировать аккаунт, прочитайте следующий раздел.

Изображение с названием Become Root in Linux Step 4

Обратите внимание на приглашение на ввод команды (в окне терминала). Если вы получили права суперпользователя, в конце приглашения на ввод команды вместо значка $ появится значок # . [2] X Источник информации

Изображение с названием Become Root in Linux Step 5

Введите команды, на исполнение которых нужны права суперпользователя. После входа в систему с помощью команды su — и получения прав суперпользователя можно запускать любые команды, которые требуют административного доступа. Активность команды su — сохраняется до конца сессии, поэтому пароль суперпользователя не нужно вводить каждый раз, когда необходимо выполнить очередную команду.

Изображение с названием Become Root in Linux Step 6

  • Введите sudo команда и нажмите ↵ Enter (например, sudo ifconfig ). Введите свой пароль пользователя, а не пароль суперпользователя.
  • Команду sudo рекомендуется использовать в некоторых дистрибутивах Linux, например, в Ubuntu, потому что она работает даже тогда, когда учетная запись суперпользователя заблокирована.
  • Эта команда доступна пользователям с правами администратора. Добавить или удалить пользователя можно в /etc/sudoers .

Источник

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