In this article, we are going to learn about how to get root access in Ubuntu 22.04. By default root user is disabled in Ubuntu. We can not log in as root. But we can log in into the terminal if we want.
What you’ll learn
- How to set the root password
- How to enable the root user
- Some basic configuration
What you’ll need
- Ubuntu Desktop
- Sudo-privileged user account
- Basic Linux command line knowledge
How To Get root Access:
In Ubuntu by default, we have to log in as non-root users, and then we have to set the root password by ourselves. The first time we don’t know the root password so we can not log in directly that is why we had to log in as a non-user which is created while we install Ubuntu.
Check login user
Now, first of all, you have to open the terminal and you can check the current login user with the help of whoami
command.
$ whoami
Login as root in the terminal
Now we have to switch the user non-root to root so you have to type the command in the terminal as sudo -i
and hit enter.
$ sudo -i
Check the root login or not?
Now you can check you are in the root you can identify with the symbol of #
as well as you can type the same command whoami
.
Set the Ubuntu root password
Now you have verified the current login user in the terminal is root
so you have to type passwd
command and hit enter, it is asking for a password so you have to enter the password and then verify the password, and that is it, you have set the root password using the terminal.
# passwd root
Enable the root login
We have to edit the following file to enable the root login. After editing the following file we can able to log in as root
.
# nano /etc/pam.d/gdm-password
In this file we have to comment on the second line: auth required pam_succeed_if.so user != root quiet_success
#%PAM-1.0auth requisite pam_nologin.so#auth required pam_succeed_if.so user != root quiet_success@include common-authauth optional pam_gnome_keyring.so@include common-account# SELinux needs to be the first session rule. This ensures that any # lingering context has been cleared. Without this it is possible # that a module could execute code in the wrong domain.session [success=ok ignore=ignore module_unknown=ignore default=bad] pam>session required pam_loginuid.so# SELinux needs to intervene at login time to ensure that the process# starts in the proper default security context. Only sessions which are# intended to run in the user's context should be run after this.# pam_selinux.so changes the SELinux context of the used TTY and configures# SELinux in order to transition to the user context with the next execve()# call.session [success=ok ignore=ignore module_unknown=ignore default=bad] pam>session optional pam_keyinit.so force revokesession required pam_limits.so
Login as root in Kali Linux
Now you can exit from the root
user and close the terminal and log out from the non-root
user and log in with the root
user with the help of a new password.
That’s it this is the way how you can change the root password and log in with the root
user.
Video
You can watch the following video where I show step by step how you can get root
access and how you can change the password.
Conclusion
So this is the way how to enable root
the user and log in as root
on Ubuntu 22.04 LTS. But login with root
means you are the super user and you have many responsibilities.
If you have any questions, feel free to leave a comment.
Related Posts: