Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This question already has an answer here:

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?

share|improve this question

marked as duplicate by muru, belacq, Vojtech Trefny, Tim, mikewhatever Aug 16 at 9:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
Check /etc/ssh/sshd_config to see if root login is allowed. –  saiarcot895 Aug 15 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. –  Michael Ozeryansky Aug 16 at 2:38
1  
@MichaelOzeryansky i can use su or sudo -i but i need to use ssh root@my-ip. –  user2517728 Aug 16 at 6:27
    
@saiarcot895 i check it, but still i can't login as root. –  user2517728 Aug 16 at 6:28

4 Answers 4

up vote 7 down vote accepted

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.

share|improve this answer
    
I add PermitRootLogin yes and restart ssh service. but ican't connet with root@ip. it returns Access Denied –  user2517728 Aug 15 at 21:34
2  
@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 at 9:41

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

share|improve this answer
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. –  Eliah Kagan Aug 16 at 2:14

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.

share|improve this answer

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. SIMPLE!

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.