SSH-keygen: Unable to use same public key in a different server

Hello,

I have created a key pair and able to login without password in devapp01. I am trying to repurpose the same key to ssh to devdb01. I can see the same public key has been copied to both the different systems. But every time I try to ssh to devdb01, it still asks for password.

Note: Just to add, this activity is not to answer any question asked in lab. I am just trying to do out of curiosity if a public key which is used in sever 1 can be used in server 2 as well or not.

bob@devdb01:~$ cd .ssh
bob@devdb01:~/.ssh$ ls
authorized_keys
bob@devdb01:~/.ssh$ cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTeJ2bGv3SbdHJ8+xwT6rjXuR63PmF2i+cV1LYLwKtF1iO6Uw4CHqwEY5M0Ek/Nzc+0GL+hh4ZUCPRHVnX9ZYCY0on0wOj27PTUdLGVFxslW0b9nradiLXFM2y26BlyO7W6+IdA/2Vdl4uu1PX2I6NAk7IyS4bY4JYiFFh+AeS5lIpXsDfwGNt5i1GA16MGivKQXNdYK30JhA3IaQOIySiw6KUUNB5SQu+CGZsi86gTA0ZiRSDz44DktyiJQ13jqwaWr9C9CUaicY1a+SciKx0yejzfWh0VpLmPUpXkYHqs2k/V2ZaJ51C3x4tsUmNafWmeVEonF17sTo7caAtR/Qd bob@caleston-lp10
bob@devdb01:~/.ssh$ exit
logout
Connection to devdb01 closed.
bob@caleston-lp10:~$ ssh bob@devapp01
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-101-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, you can run the 'unminimize' command.
 _______  _______  _        _______  _______ _________ _______  _
(  ____ \(  ___  )( \      (  ____ \(  ____ \\__   __/(  ___  )( (    /|
| (    \/| (   ) || (      | (    \/| (    \/   ) (   | (   ) ||  \  ( |
| |      | (___) || |      | (__    | (_____    | |   | |   | ||   \ | |
| |      |  ___  || |      |  __)   (_____  )   | |   | |   | || (\ \) |
| |      | (   ) || |      | (            ) |   | |   | |   | || | \   |
| (____/\| )   ( || (____/\| (____/\/\____) |   | |   | (___) || )  \  |
(_______/|/     \|(_______/(_______/\_______)   )_(   (_______)|/    )_)
Last login: Sun Aug  9 22:33:36 2020 from 172.16.238.187
bob@devapp01:~$ cd .ssh/
bob@devapp01:~/.ssh$ cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTeJ2bGv3SbdHJ8+xwT6rjXuR63PmF2i+cV1LYLwKtF1iO6Uw4CHqwEY5M0Ek/Nzc+0GL+hh4ZUCPRHVnX9ZYCY0on0wOj27PTUdLGVFxslW0b9nradiLXFM2y26BlyO7W6+IdA/2Vdl4uu1PX2I6NAk7IyS4bY4JYiFFh+AeS5lIpXsDfwGNt5i1GA16MGivKQXNdYK30JhA3IaQOIySiw6KUUNB5SQu+CGZsi86gTA0ZiRSDz44DktyiJQ13jqwaWr9C9CUaicY1a+SciKx0yejzfWh0VpLmPUpXkYHqs2k/V2ZaJ51C3x4tsUmNafWmeVEonF17sTo7caAtR/Qd bob@caleston-lp10
bob@devapp01:~/.ssh$ exit
logout
Connection to devapp01 closed.
bob@caleston-lp10:~$ ssh bob@devdb01
bob@devdb01's password:
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-101-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, you can run the 'unminimize' command.
 _______  _______  _        _______  _______ _________ _______  _
(  ____ \(  ___  )( \      (  ____ \(  ____ \\__   __/(  ___  )( (    /|
| (    \/| (   ) || (      | (    \/| (    \/   ) (   | (   ) ||  \  ( |
| |      | (___) || |      | (__    | (_____    | |   | |   | ||   \ | |
| |      |  ___  || |      |  __)   (_____  )   | |   | |   | || (\ \) |
| |      | (   ) || |      | (            ) |   | |   | |   | || | \   |
| (____/\| )   ( || (____/\| (____/\/\____) |   | |   | (___) || )  \  |
(_______/|/     \|(_______/(_______/\_______)   )_(   (_______)|/    )_)
Last login: Sun Aug  9 22:44:08 2020 from 172.16.239.187
bob@devdb01:~$

Hello @KodeKloud @kodekloud-support3

Can you help me to understand this or guide me somewhere?

Hello praddasg,

not sure if you’ve already figured this out.
Sounds like the public key is not working. sshd is since it is asking you for a password. Did you copy paste the key? Sometimes by copy-pasting spaces or special characters are copied as well, so the key does not work.
Try this to copy the key without the above problem:
Copy public_key to node server
$ ssh-copy-id user@nodeIP

Let me know if it worked for you!
Best

Thanks for responding @msgeek, If i recollect correctly, I did use the above command, instead of using cp command. I will try again in local to check if this is working

Hello, @praddasg
If you did copy public key in the respective server then you can do ssh without password. You can perform the below steps.
ssh -i $HOME/.ssh/id_rsa user@IP-addr

1 Like