Ubuntu: Allow SSH access for ‘root’ user

KB ID 0001317 


First of all not being able to connect to your Ubuntu server via SSH as root is ‘by design’, and it’s a perfectly good security measure. I do find it interesting that every hosting company I ever used, spin up a new machine and then email me the root password and they’ve enabled it anyway?

I needed to enable this recently and the internet is full of posts saying ‘just edit the config file, and restart the service’. What they don’t tell you is that the root user is disabled by default, even with a valid password, IT STILL WONT WORK!


Connect to your Ubuntu machine, and reset the root user password, (so you know what it is).

sudo passwd root

Reset Root Password

As shown you will need to enter your password first, then enter and confirm a new root password.

Then ‘unlock the root account’;

sudo passwd -u root

Unlock the root account

Note: If you ever want to ‘lock‘ it again, use (sudo passwd -l root).

Now you can edit the sshd config file;

sudo nano /etc/ssh/sshd_config

Locate the line ‘PermitRootLogin’ and change it so it ONLY says yes (as below).

Change SSH Port and Allow Root

Note: Here I’m also changing the SSH port (to 2223 in this example, from the default port of 22), I usually change the default SSH port.

Now finally, restart the SSH Daemon, (that always looks like it’s spelled incorrectly!) With the following command;

sudo service sshd restart

Don’t forget if, (like me) you changed the port, you will need to specify that in your client connection software (i.e. PuTTy or RoyalTSX).

Related Articles, References, Credits, or External Links


Author: PeteLong

Share This Post On

1 Comment

  1. thank you, this helped me so much

    Post a Reply

Submit a Comment

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