Linux logging on as root

How do I become superuser on Ubuntu Linux using su/sudo?

I replaced Windows 10 with Ubuntu Linux 16.04 LTS. So, I am a new Ubuntu Linux user. How do I become superuser on Ubuntu Linux? How do I login as root on Ubuntu?

Introduction: On Ubuntu Linux root is a particular user account. By default, the root user has access to all commands, files, services on an Ubuntu Linux operating system. It is also known as the root account, root user and the superuser. The superuser or root user has root privileges. It is the most privileged account on Ubuntu with complete access to everything. The MS-Windows equivalent of root is the Administrators group or Administrator user. This page shows how to log in as root or superuser on Ubuntu to perform sysadmin related tasks.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Ubuntu Linux
Est. reading time 3 minutes

How to become superuser on Ubuntu Linux

  1. Open a terminal Window/App. Press Ctrl + Alt + T to open the terminal on Ubuntu.
  2. To become root user type:
    sudo -i
    OR
    sudo -s
  3. When promoted provide your own password.
  4. After successful login, the $ prompt would change to # to indicate that you logged in as root user on Ubuntu.
  5. You can also type the whoami command to see that you logged as the root user.

Let us see all commands and examples in details.

How do I login as root on Ubuntu?

Open the Terminal application. Use the whoami command to verify user identity:
$ whoami
To login as root on Ubuntu, type the following sudo command:
$ sudo -i
Next type your password and your shell promot should change from $ to # :
#
To exit from sudo session of root user, type any one of the following exit command or logout command:
# logout
OR
# exit

  • 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

How to become superuser on Ubuntu Linux using sudo command

The -i option tells sudo to run the shell specified by the root user’s password database entry as a login shell. If you pass the -s to the sudo command, it runs the shell specified by the SHELL environment variable if it exists or the shell defined by the invoking user’s password database entry.

How to become root in Ubuntu Linux using su

By default, the root account password is locked in Ubuntu Linux for security reasons. This means that you cannot login as root directly or use the su command to become the root user. You must set up root password by running the following command in advance on Ubuntu based system:
sudo passwd root
See “How to change root password in Ubuntu Linux” for more info.

Type the following su command:
$ su —
You must know and type root user’s password when prompted:

Login as root on Ubuntu Linux using ‘su -‘ command

su vs sudo to become superuser in Ubuntu Linux

Table 01 – Difference between su and sudo
su command sudo command
You must know the root user’s password. No need to know the root user’s password.
The su command does not log usage or all arguments. The sudo command logs sudo usage and all arguments.
If the root user password not set or root user is disabled, you can not use su command. sudo works with or without a root user password. It uses your password and /etc/sudoers file to authenticate your session.

Conclusion

This tutorial explains how to gain root access in the Ubuntu Linux terminal session using the sudo and su command. I recommend that you always use the sudo command to become root user on Ubuntu. For more info see this page.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Источник

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.

Источник

How Can I Log In As root User?

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements su/sudo
Est. reading time Less than a minute

It is not good a 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.

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.

su command syntax

If invoked without a user-name, su defaults to becoming the super user. The user will be prompted for a password, if appropriate.

To log in as root user type the following command (you need to supply root user account password when prompted):
$ su —
Sample outputs:

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

Remote root login over the ssh session

You can use the ssh client as follows:
$ ssh root@server.ip-address-here
$ ssh root@server1.cyberciti.biz
$ ssh root@1.2.3.4
However, remote root login over ssh session is disabled in most cases for security reasons. First, login as a normal user and then switch to root account using the su command:

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:
# tail -f /var/log/secure
Debian / Ubuntu Linux user try:
# tail -f /var/log/auth.log
Sample outputs:

Say hello to sudo command

The sudo is a program for Linux / Apple OS X / *BSD / Unix-like computer 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. Apple Mac OS X and Ubuntu Linux and many other oses uses sudo command for many administrative tasks.

  • 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

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 example, to login as root under Linux or Unix like operating system, type:
$ sudo -s

Sample sudo command session

Fig.01: Switching to root account using sudo command

Sudo and log file

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

See also
  • Linux Run Command As Another User – Explains how to run run Linux commands as another user or run commands as root user using runuser, su, and sudo utilities.

🐧 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 have installed ubuntu and always log in as user. I have read the HOW TOO’s but I am confused by the comment ‘Make sure you use the root password.’ How can you use a root password when you haven’t got one (I think) because the only password I use is the password I gave when I installed Ubuntu (dapper Drake). Is this a root password also if you say it’s root as time of login. If you have to have a seperate login root password – How do you get it? Thanks john6.

By default, the root account password is locked in Ubuntu. This means that you cannot login as root directly or use the su command to become the root user. However, since the root account physically exists it is still possible to run programs with root-level privileges.

Hmmm, lets see Can not log in as : \ SU Thought Ubuntu is open source The only why you can adjust the Kernel is as root. what they hiddin willis.

opp’s should have read more of the reply’s. but as a openBSD user never really had this issue.

Thank you very much for this help!

To all the latin people…..here is the answer in spanish:

Escriban “su -” para cambiar al root. Les pedira la clave del root.

Escriban “su – gon” para cambiar al usuario llamado gon. Les pedira la clave.

John.
You can change your root password by typing in console” sudo passwd root ” By doing this i had to enter my user password then set a new root password and repeat it.

Baller. That was perfect. Thank you.

thnx. by default there is no password for root, hve to get by typing ”sudo passwd root”.

Thanks for this article and to AIS/fahim for the additional information about how to change the root password! Just what I was looking for.

AIS, thanks a lot

The question is still unanswered.

To login as root is very convenience and very important for some applications. Without it, you may not be able to run those programs at all. Su is good but with great limitation.

So if anyone who know the answer, please help. We do not need advise about workaround.

After 5 minutes of browsing on the Internet, I found it is very easy to make the changes so you can login as root from GUI. This is for Fedora 11:

First, (dangerous?) you must su and login as root then cd to /etc/pam.d
There are two files: gdm and gdm-password. Use your editor and
Comment this statement for both files:

# auth required pam_succeed_if.so user != root quiet

Save and logout. Try login as root. You should be.

After login as root and play around, I found the above changes were not enough. Thanks to my-guides.net, I found the last piece that fixed the problem.

You need to edit another file: /etc/PolicyKit/PolicyKit.conf
and add
between .

That will do the job.

The missing statement between is

Thanks a tonnnnn Gregory. Somehow I could never find the answer for this , instead of getting ridiculed for wanting this. 🙂

Thanks for command “sudo passwd root” !!

you didn’t answer the question!

you condescendingly gave some “best practices” advice, and then proceeded to explain out how to do something else.

I have to agree that the entire tenor of this conversation is offensive. Crossing the street is dangerous, also, but I do it anyway. My mother taught me the risks when I was quite small, as well as how to do it safely. If you really want to keep UBUNTU safe from learning problems, I suggest that you lock down the entire system and send us all to a Windows app.

Instead, please stop insulting all of us who are adults and capable of taking our own risks. I need to open the folder /etc/openvpn using my GUI and add a file to the folder. Stop patronizing me and tell me how to do this please.

I agree whole-heartedly. Uber-geek Linux users can be extremely condescending. I’ve had them to tell me to RTFM. Which one? The “right” one”? The “other” one. The one that applies to my distro? Oh wait, that distro has tons of bugs, but the upcoming distro gives you a workaround. RTFM!
How bout this? FTFM ! FIX it. Fix all the crappy and conflicting documentation. Yeah, this thing is “free”. But when all the wasted time getting things to work is considered, it’s more expensive than products from The Dark Empire. Bottom line is, if you’re going to do something, whether it’s for free or not, do it right and make it work like you say it does. Or don’t do it at all.
You people have a lot of nerve criticizing Windows when you worship a product that is a stone’s throw away from hieroglyphics and documented in glyphs.
Cheers, ubers …

I agree wholeheartedly. I need Linux for a project, but it, and all other Linux distros I’ve used, seems to be dwelling in the past, and the developers delight in their backward approach and to delight in making things difficult. Personally, I think it’s almost up to the Windows 98 point, but not quite there yet….

Источник

Читайте также:  Cron linux запустить скрипт
Оцените статью