0

I want to use remote explorer in VS Code on Windows to access a server from Ubuntu. Entering a password all the time is annoying, so I tried generating an ssh key using ssh-keygen. The key works fine for a normal user, but I can't login as root.

The error from cmd (ssh root@<server_ip>):

root@<server_ip>: Permission denied (publickey,password). 

The error in /var/log/auth.log :

sshd[1012327]: Connection reset by authenticating user root <client_ip> port 59021 [preauth] 

All of the solutions I've seen mentioned sshd_config, but root login is enabled in it. sshd_config:

# Authentication: #LoginGraceTime 2m PermitRootLogin yes #StrictModes yes #MaxAuthTries 6 #MaxSessions 10 PubkeyAuthentication yes # Expect .ssh/authorized_keys2 to be disregarded by default in future. #AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2 #AuthorizedPrincipalsFile none #AuthorizedKeysCommand none #AuthorizedKeysCommandUser nobody 

I have added the public key to the /home/user/.ssh/authorized_keys file. It seems to me that this key is only for the user, but from the guides it seems that I can use it for root as well.

So why can't I connect as root?

3
  • For some reason someone deleted their answer, but it worked for me. Just added my key to the /root/.ssh/authorized_keys and now everything works fine. I didn't understand how people add a key to user and get access to root. It seems that everyone just means that this should be done by analogy Commented Jul 12, 2023 at 18:13
  • Answer undeleted. I wasn't sure what role Windows plays here and if it complicates things maybe. Commented Jul 12, 2023 at 18:14
  • Thank you! Sorry for such a simple question. Commented Jul 12, 2023 at 18:17

1 Answer 1

2

It seems to me that this key is only for the user, but from the guides it seems that I can use it for root as well.

The guides have misguided you.

Each user has his or her own home directory and thus his or her own authorized_keys. Root's home directory is usually /root/. Therefore the relevant file for logging in as root is /root/.ssh/authorized_keys. It has nothing to do with /home/user/.ssh/authorized_keys.

Think about it. /home/user/.ssh/authorized_keys belongs to user user which is a regular user and may or may not have sudo access. The user can register any key there. If root used the same file then the user would be able to log in as root just by authorizing some key.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.