1

I have a VPS with Ubuntu 14.04. I need to login as root to my server over SSH.

I set a password for root: sudo passwd root
then enabled it: sudo passwd -u root
then rebooted my vps: sudo reboot

But I still can't connect with the root user. How can i enable ssh login as root?

4
  • 2
    Check /etc/ssh/sshd_config to see if root login is allowed. Aug 15, 2014 at 21:15
  • 1
    On my server I disabled root login, but gave my user sudo access. So I login with my account, then sudo su when I need root. Aug 16, 2014 at 2:38
  • 1
    @MichaelOzeryansky i can use su or sudo -i but i need to use ssh root@my-ip. Aug 16, 2014 at 6:27
  • @saiarcot895 i check it, but still i can't login as root. Aug 16, 2014 at 6:28

4 Answers 4

7

The default on Ubuntu 14.04 in /etc/ssh/sshd_config is

PermitRootLogin without-password

which forbids root logins using password authentication. This is a good idea because brute-force login attempts against the root user are extremely common.

To login as root, I recommend setting up key-based SSH login. Another (dangerous!) possibility is to change the option to PermitRootLogin yes.

2
  • I add PermitRootLogin yes and restart ssh service. but ican't connet with root@ip. it returns Access Denied Aug 15, 2014 at 21:34
  • 3
    @user2517728 I have to wonder: If you're still having problems after following this answer's instructions, how is this the accepted answer?
    – Alex
    Aug 16, 2014 at 9:41
2

This doesn't answer the question directly, but if your intent is simply to administer your machine remotely, it is generally considered preferable and safer to log in as a non-root user, then elevate your privileges once you have started a session on the server.

In other words, instead of using ssh root@yourserver, you may wish to log in as yourself (your own distinct username and account) then run sudo bash or even su and to authenticate as root once logged in. You can also prepend most commands with sudo to have that command run with root's privilege level, e.g.,:

sudo cp /etc/configthing.conf /etc/configthing.conf.orig or

sudo rm -i /var/log/syslog.3.gz

1
  • 2
    @belacqua This answer is suggesting to SSH in as a non-root user and then use sudo or su to elevate to root. This is the preferred way to administer a system remotely via SSH (including on OSes were the root account is enabled by default). I don't think the OP said they tried this--instead, they said they'd run the passwd command with sudo. While the alternative presented here arguably does not match the OP's parameters, this may be an XY problem, and the disadvantages of allowing remote root logins are enough that we should probably keep this. Aug 16, 2014 at 2:14
1

If you insist on having to log in as root, I'd suggest logging in as a normal user, running

sudo tail -f /var/log/auth.log

and then (without closing that session), trying to log in as root via SSH and observe the authentication error messages appearing in the first session.

You should be able to figure out the reason you're unable to log in as root from there, otherwise posting /etc/ssh/sshd_config might get you an answer more quickly.

0

There are many examples online so I will not repeat them.

The one thing they do not say is you need:

ssh-add [path_to_key]

when using a custom name (not default) for the key.

If you insist on only using a password not a public-private key pair:

ssh root@server-ip-or-hostname

and type your pass.

Not the answer you're looking for? Browse other questions tagged .