Ubuntu – SSH Key-Based Authentication to Ubuntu fails for “No such file or directory”

sshUbuntu

I am trying to access my vps using SSH Key-Based Authentication.
this is what i tried:

1.create a public and private key in Windows using PuTTYgen

2.copy the one line format of the public key to a this file /home/username/.ssh/authorised_keys
this is how the key looks like:

ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEAxjoUKeoEWdpazINZ1WmEiierZ1eC/OtQ6r0MFBofBg3oSvzF0o3mqzJB2rklNAcFoiQ/MHB5nk7lLfb82Ny7np9vYXoprZinM68PSjfhNd20QfXRJfeTaKZqWtzv64r+zOPs3n32FEfSY5x5numk6YqZ1AjbwyU2/HhEUN35FzyjofZjCiR9BM5eaylf8yJ/fgHVoFBVuL7N5jsbPG6fP2ZEIGSBFH6DCN+HEpvySFzdgy2KkznRl0/o1dWc3FU8NaqZG+M1JZzEIjehEuaVwMFrIQxdHXoZCY7OJHHwWFOQCWhYScTh3PeOnvPnU6LYBLgAG+felrdQrho2My9jxw== rsa-key-20191225

3.sudo chmod 700 ~/.ssh

4.sudo chmod 600 ~/.ssh/authorized_keys

5.sudo chown -R $(whoami):$(whoami) ~/.ssh/

When I try to connect with private key loaded in PuTTY I get this error in the log:
`

Dec 26 00:27:34 berbidserver sshd[29601]: debug1: Could not open authorized keys '/home/tarantula/.ssh/authorized_keys': No such file or directory
Dec 26 00:27:34 berbidserver sshd[29601]: debug1: restore_uid: 0/0
Dec 26 00:27:34 berbidserver sshd[29601]: debug1: temporarily_use_uid: 1001/1001 (e=0/0)
Dec 26 00:27:34 berbidserver sshd[29601]: debug1: trying public key file /home/tarantula/.ssh/authorized_keys2
Dec 26 00:27:34 berbidserver sshd[29601]: debug1: Could not open authorized keys '/home/tarantula/.ssh/authorized_keys2': No such file or directory

`

Best Answer

But did you SSH to the server with user tarantula when you created the folder ~/.ssh and copîed the files ? My guess is, you SSHed as root, that's why the files are not found in the home directory of user tarantula. They are most likely in /root.

If you don't want to grant user tarantula SSH rights, what you could do is:

  1. SSH to the server as root
  2. Then type: su - tarantula to log in as tarantula
  3. once you're logged in as tarantula, add the .ssh folder if it doesn't already exist, copy the files