- How to become root in Linux
- Logging in as root
- Running commands as root without the root password
- Linux Login as Superuser ( root user )
- Linux superuser
- Linux Login as Superuser
- How to become superuser in Linux
- Become a superuser in Linux using sudo command
- Superuser login
- How to become Root user in Ubuntu Command Line using su and sudo
- What is a Root user?
- About the Article
- How to become root?
- Get Temporary root access through the sudo command
- Unlock/lock root account
- How to change the root password (An alternative approach)?
- Karim Buzdar
How to become root in Linux
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 allows you to run commands as the root account temporarily. From the command line, type:
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 allows you to safely edit the sensitive sudoers file.
Источник
Linux Login as Superuser ( root user )
Linux superuser
In Linux and Unix like computer operating systems, root is the conventional name of the user who has all rights or permissions (to all files and programs) in all modes (single- or multi-user). The root user can do many things an ordinary user cannot, such as changing the ownership of files and binding to ports numbered below 1024. The etymology of the term may be that root is the only user account with permission to modify the root directory of a Unix system.
Linux Login as Superuser
You need to use any one of the following command to log in as superuser / root user on Linux:
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
- su command – Run a command with substitute user and group ID in Linux
- sudo command – Execute a command as another user on Linux
How to become superuser in Linux
Let us see some examples of the su and sudo command to become superuser in Linux.
Become a superuser in Linux using sudo command
You must be part of special secondary group on Linux:
- sudo group on a Debian or Ubuntu Linux
- wheel group on a CentOS/RHEL/Fedora/Oracle Linux
You can see your secondary group membership by running either groups command or id command $ groups
$ id
Next run the following command to become a root/super user:
$ sudo -i
When promoted type your password to gain root shell.
Log in as a superuser/root user using the sudo command on Linux
Superuser login
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Category | List of Unix and Linux commands |
---|---|
Documentation | help • mandb • man • pinfo |
Disk space analyzers | df • duf • ncdu • pydf |
File Management | cat • cp • less • mkdir • more • tree |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Linux Desktop Apps | Skype • Spotify • VLC 3 |
Modern utilities | bat • exa |
Network Utilities | NetHogs • dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop |
Searching | ag • grep • whereis • which |
Shell builtins | compgen • echo • printf |
Text processing | cut • rev |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
i like to learning more about linux
It is interesting to notice how easy it is to find this information on the web, how to login as a superuser, and how it is difficult to find the information about how to log OUT of superuser (exit). Wouldn’t it make sense to put these things together ? I guess that someone who just learnt how to log in as a superuser would also immediately need to know how to log out.
And by the way, your answer after “A” doesn’t answer the questions “Q” at the beginning of the article.
Hey, i tried this but my linux said:
Error with approval ( think thats how you translate it..
its bothering me alot and i tripple checked the password it is correct
what version of lunux are you using? if you are using any ubuntu based linux for example you, you can only use the super user to run comands, you cant stay loged in as the super user.
Ex: to install an aplication, you would opne a terminal and enter
sudo apt-get install name_of_application.
the sudo or su comand will indicate to linux that you are trying to run the comand as the super user or administrator, but in ubuntu after the application is done installing it will go back to regular user to aboid any security breach. y have to realize that the when you are in super user mode it can be verry danguros becasue bc you can do anything, like deleting all you files and messing up your operating system.
so in conclution you get that message because your linux you might not be running any other comands after the sudo or su comand.
i hope that made sense.
i am grave trouble i forgot ma superuser password hw to recover it
I am new to linux, i want to learn more about linux as much possible. i am using ubuntu and suse.
i try to log in as supper user by su command, and provide password i used to login my system but it shows Authentication failure. please guide me.
Thanks and regards
Earlier i used to login to root by typing ip address and port, i just remember the ip address but i forgot the port number, can anybody please help.
I think you are using telnet or ssh, if telnet it is port 23 and for ssh it uses port 22. Hope it helps.
i just now logged in as super user but i want to delete it.what i should do for that.
All you need to do is type: Exit
or press Control D
thanks for this! learning linux command line scripts now after installing fedora in my nephew’s inspiron 1525, was wondering how to get to root user, other sites weren’t explaining well enough so again, thanks a million! 🙂
Being a super user can be VERY dangerous so I suggest you know what your doing if your going to become a super user but another way to get root access is to type into the command line:
Источник
How to become Root user in Ubuntu Command Line using su and sudo
What is a Root user?
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 18.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.
The system will ask you the password for root. Enter the password and hit Enter.
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.
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. Advertisement
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’
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:
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.
You can, however, unlock it by entering the following command as sudo:
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.
After you are done with performing your root operations, you can lock the root account again by entering the following command:
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.
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:
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!
Karim Buzdar
About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn
Источник