Getting password prompt in SSH connection even after setting public key in target host authorized_keys file
Recently, I reinstalled an Ubuntu server due to corruption of its root file system. After the installation, I remounted the old home
directory and tried to access the server with SSH.
However, I kept getting password prompt even after I have configured my public key in ~/.ssh/authorized_keys
.
After googling and looking into the verbose logs of SSH connection, I found that it’s because the newly created user (I need to add all the users again in the newly installed system) has different Linux uid
with the user in the old Ubuntu system. The ls
result of my server looked like the following:
user@localhost:~$ ls -al /home/
total 56
drwxr-xr-x 11 root root 4096 Apr 24 2018 .
drwxr-xr-x 24 root root 4096 Jun 16 11:17 ..
drwxr-xr-x 13 1234 1234 4096 Jun 20 23:48 user
I wasn’t able to access my “old home
directory” because I didn’t own that directory. The user id of my new user is not 1234. After updating the owner of the home
directory. I was able to access my server without password prompt.
By the way, I also found that there are several reasons a user gets password prompt even with SSH key configured:
- The user is set with shell that is not install in the system
~/.ssh
directory doesn’t configured with right permission
You could check the reference for more detailed explanation for the two situation above.
Hope this will help someone with the same problem like me.
Reference:
Why am I still getting a password prompt with ssh with public key authentication?