2

What I have done

  1. created a new digital ocean droplet and
  2. Created SSH key based on this guide and during the creation of the droplet I have copied it in
  3. I have run the following codes from here
ssh root@your_server_ip
adduser sammy
usermod -aG sudo sammy
  1. Than I have tried to log in as "sammy"
ssh sammy@your_server_ip

ERROR

  • Permission denied (publickey).
  • If I log in with root access than there is no problem I get in like before

Fixes I have tried

  1. cleaned put the shh key folder and only have this key there
  2. I haven't found any answer but my problem is kind of like this
  3. this is not that similar to this.
  4. ssh -vvv root@my_ip from here it pushes out like lines of debug what should I look for?
  5. I have tried to read sshd server logs on ubuntu this most common messages
Disconnected from invalid user somefirstname43
Disconnected from invalid user someotherfirstname334
Disconnected from authenticating user root
Received disconnect from ID port ...
Accepted publickey for root from ID
Did not receive identification string from  ID port ....
Connection closed by authenticating user sammy ID port portnumber  <<----
sogu
  • 183
  • 2
  • 3
  • 11

2 Answers2

2

Your user sammy needs the public key you used to login to the root user. The easiest way is to copy the authorized_keys file from your root user.

mkdir ~sammy/.ssh
chmod 640 ~sammy/.ssh
cp ~/.ssh/authorized_keys ~sammy/.ssh/
chown -R sammy:sammy ~sammy/.ssh/
Gerald Schneider
  • 19,757
  • 8
  • 52
  • 79
  • Question when you say ```authorized_keys``` I just type that or where is the authorized_keys ? – sogu Mar 18 '20 at 17:49
  • `authorized_keys` is the file where the authorized public keys are stored. It is located in the `.ssh` directory in the users home directory. Theoretically you should be able to run the commands via copy&paste (as root). – Gerald Schneider Mar 18 '20 at 17:51
  • I have typed in everything that you said only replacing "sammy" with my actual user name. I double checked, but when I try to log in with the other user still get ```Permission denied (publickey).``` – sogu Mar 18 '20 at 17:54
  • then it's time to read the sshd server logs for actual error messages. – Gerald Schneider Mar 18 '20 at 17:55
  • by the way I have only added the public key to my droplet during configuration. And than I only have done the commands that I show in my description – sogu Mar 18 '20 at 17:55
  • I have tried ```ssh -vvv root@my_ip``` from [here](https://www.digitalocean.com/community/questions/ssh-permission-denied-publickey) it pushes out like lines of debug what should I look for? – sogu Mar 18 '20 at 18:00
  • Read the error logs on your server. Your client can't tell you what's the problem because it doesn't know. – Gerald Schneider Mar 18 '20 at 18:00
  • How can I do that, like [this](https://serverfault.com/a/480433/535406)? – sogu Mar 18 '20 at 18:01
0

There is an answer for this on Digital Ocean

1.Log in as root ssh root@IP

2.Edit ssh config: sudo nano /etc/ssh/sshd_config

3.Change this line: PasswordAuthentication no to PasswordAuthentication yes

4.Restart daemon: sudo systemctl restart sshd

5.Do ssh-copy-id: ssh-copy-id someuser@IP (if you already have a key there it may not allow you to copy so just skip this step and log in with the next step)

6.Log in as the new superuser you have created before ssh someuser@IP

7.Revert changes to ssh_config if you are security conscious and restart daemon.

Peta
  • 116
  • 4