15

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.

Richard
  • 1,927

7 Answers7

24

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

11

If you decide to use the root account.

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 brute force attacks against your computer. Since its harder to guess both the user and password. Knowing the username one would only have to brute force the password

changing the line:

PermitRootLogin yes

under /etc/ssh/sshd_config

to

PermitRootLogin no

and run:

service sshd restart

to reload the configuration.

tomodachi
  • 15,370
8

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.

Bruno Pereira
  • 74,715
4

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

sudo grep root /etc/shadow

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).

You should not enable the user root for security reasons.

muru
  • 207,228
user827992
  • 2,901
1

set root password using following command

sudo passwd
D Nilesh
  • 171
0

Just to be clear, the password you use at the sudo prompt when running a sudo command as a regular user is NOT your root password. It is the password for the current user. It is this ambiguity that usually bring people to this question.

If you are already in a root terminal, you can set the root password as mentioned by @Manula by using:

passwd

If you are logged in as a regular user, log in as root first:

sudo -i
passwd

WARNING: This however makes your root account vulnerable to brute-force ssh attack via whatever network you are on (including the Internet - depending on your network and firewall configurations).

I tried the answer by @Bruno while configuring an ssh key for the root account and I still needed to set a password for root.

For me, the best and most secure option is to NEVER set a root password. You can still run ssh commands from your root terminal but as a normal user; assuming you have a user named paul:

ssh paul@localhost

Only requirement is that you have to setup ssh for user 'paul', while logged in as 'paul':

sudo apt install openssh-server
ssh-keygen -t rsa -b 4096
ssh-copy-id ${USER}@localhost
-1

They answered your question about login to ssh with non super user (say goblin@192.168.0.3 -p 22).

First create another account without su privleges. After you log into ssh as a non super user you can enter this command to switch to root (escalate your privileges):

su

And enter password.

muru
  • 207,228