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.

I need to ssh to localhost using root account, by ssh root@localhost. When it prompts for passwords, I can not login with all possible passwords. On setting of localhost machine, regular user xxx and root user share the same password (the password that works for sudo -s), but it does not works for ssh root@localhost. So where to look at the password for ssh root@localhost

PS: with the password, I can login to regular account on ssh xxx@localhost.

PPS: to answer further questions on motivation of doing so, localhost is just a computer in a private network and setting up ssh root@localhost is just to relieve some manual management in a prototype system.

share|improve this question
1  
Are you doing this in a script, or is this for interactive use? If interactive, why not just log in as some other user and then use sudo as needed? If for a script, then you really shouldn't be using password authentication anyway, since it means you have to put the password in plaintext in the script. –  Daniel Pryden Aug 3 '12 at 15:46
    
I am doing this in a script, but a passphraseless ssh based on public/private key is intended to setup, so password is not really stored in plaintext. Good comments, though –  Richard Aug 4 '12 at 14:50

4 Answers 4

up vote 10 down vote accepted

ssh root@localhost uses the same password for root. It looks like you have not set root password. To do that log in as root using sudo -s then use passwd command to set root password.

After that you must be able to ssh as root

share|improve this answer
2  
this works. just out of curiosity, is there any difference between the root account when doing sudo -s and when doing ssh root@localhost ? –  Richard Aug 3 '12 at 12:20
1  
you should never do that, if you set a password for the user root you will enable the user root and this is a really bad move for the system's security. –  user827992 Aug 3 '12 at 13:53
    
@user827992 it is necessary to enable the user root to take advantage of ehealth-aussie.blogspot.com/2012/01/…. However, you can mitigate the security damage by disabling root login for openssh. dropbear will allow root login but only with a key and only for the brief time between power on and decryption. –  emory Aug 3 '12 at 14:56

The user root is not enabled and is not capable of doing a log in, you can see that doing so:

sudo cat /etc/shadow | grep root

the field that usually contains an encrypted password is filled with a !.

If you read the shadow(5) manpage you will get this

If the password field contains some string that is not a valid result of crypt(3), for instance ! or *, the user will not be able to use a unix password to log in (but the user may log in the system by other means).

http://linux.die.net/man/5/shadow

You should not enable the user root for security reasons.

share|improve this answer

Login as a normal user and use sudo -i to drop to a root shell.

You should not use the root account or change it's password for the matter.

share|improve this answer

If you decide to use the root account.

At least make sure to disable the ability to log in over ssh with root if ssh is exposed to internet. Instead login as a user, and su to root.

This will make sure to prevent successful brute force attacks against your computer. Since its hard to guess both the right username and password. While with root, one only has to try to guess the password

changing the line:

PermitRootLogin yes under /etc/ssh/sshd_config

to

PermitRootLogin no

and run:

/etc/init.d/sshd restart to reload the configuration.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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