How to Enable and Disable SSH Root Login Ubuntu 22.04

If you want to enable and disable root ssh login access on Ubuntu 22.04, you need to open the ssh configuration file using nano /etc/ssh/sshd_config command, set #PermitRootLogin yes to enable ssh login and set #PermitRootLogin no to disable ssh login.

Through this tutorial, we will show you how to enable or allow and disable or disallow ssh root login and limit ssh access in Linux Ubuntu 22.04.

Here are the following ways to do it:

  • Disable SSH Root Login on Ubuntu 22.04
  • Enable SSH Root Login on Ubuntu 22.04

Disable SSH Root Login on Ubuntu 22.04

If in your system the SSH root user login access is disabled and you want to enable the SSH root user login, for this you need to open the ssh configuration file and change “PermitRootLogin no” to enable or allow the SSH root user ubuntu.

To disable SSH root login on Ubuntu 22.04, you can try the following steps:

Step 1: Login and Switch As Root User

Open your terminal and switch to root user, you can do this by:

sudo -i

Step 2: Open the SSH configuration file

Now you need to open the SSH configuration file, for this you can use the command Sudo nano /etc/ssh/sshd_config:

sudo nano /etc/ssh/sshd_config

Step 3: Find the PermitRootLogin line in the File

Now the sshd_config ssh configuration file is open on your terminal, in it you have to find the “PermitRootLogin yes” line:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6

Step 4: Change PermitRootLogin to no

Now, change it to “PermitRootLogin no”

#LoginGraceTime 2m
PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6

Step 5: Restart ssh Services

Now, you need to restart the ssh service. So whatever you changed in the ssh configuration file, will take effect.

# systemctl restart sshd
OR
# /etc/init.d/sshd restart

After all, you’ve now disabled the SSH root user login. You will no longer be able to access root user login. You can also see this by trying it.

When you try to log in with the root user, Denied will be displayed in your terminal. Why have you disabled your root user login access.

Enable SSH Root Login on Ubuntu 22.04

If SSH root user login access is disabled in your system and you do not know how to enable SSH root user login. So you can enable root user login access using following commands.

To enable SSH root login on Ubuntu 22.04, you can try the following steps:

Step 1: Login and Switch As Root User

Open your terminal and switch to root user, you can do this by:

sudo -i

Step 2: Open the SSH configuration file

Now you need to open the SSH configuration file, for this, you can use the command Sudo nano /etc/ssh/sshd_config:

sudo nano /etc/ssh/sshd_config

Step 3: Find the PermitRootLogin line in the File

Now the sshd_config ssh configuration file is open on your terminal, in it, you have to find the “PermitRootLogin no” line:

#LoginGraceTime 2m
PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6

Step 4: Change PermitRootLogin to yes

Now, change it to “PermitRootLogin yes”

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6

Step 5: Restart ssh Services

Now, you need to restart the ssh service. So whatever you changed in the ssh configuration file, will take effect.

# systemctl restart sshd
OR
# /etc/init.d/sshd restart

After all, you’ve now enabled the SSH root user login. You will be able to access root user login. You can also see this by trying it.

When you try to login with the root user, The Access grant will be displayed in your terminal. Why have you enabled your root user login access.

Here is the video guide on how to enable and disable ssh root login access on Linux Ubuntu 22.04:

Conclusion

Through this tutorial, You have learned how to enable and disable ssh root login access on linux ubuntu 22.04.

Recommended Tutorials

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *