I have tried to match the public keys and private keys on both my client and server as well as the configuration files but cannot get my head around the mismatches. I can successfully connect to the server on ssh despite the mismatches. This is a bit worrying.
I will show exactly what is stored where.
Client: Mac Server: Ubuntu (hosted on AWS)
Files on my local mac /Users/sm/.ssh directory
ls -la
Sanjays-iMac:.ssh sm$ ls -la
total 24
drwx------ 5 sm staff 160 26 Nov 21:29 .
drwxr-xr-x+ 59 sm staff 1888 26 Nov 21:29 ..
-rw------- 1 sm staff 1696 26 Nov 20:49 id_rsa
-rw-r--r--@ 1 sm staff 451 26 Nov 20:50 id_rsa.pub
-rw-r--r-- 1 sm staff 1151 26 Nov 21:08 known_hosts
Files on my ubuntu server:
ubuntu@ip-172-31-30-19:~/.ssh$ ls -la
total 12
drwx------ 2 ubuntu ubuntu 4096 Nov 26 14:37 .
drwxr-xr-x 8 ubuntu ubuntu 4096 Oct 30 18:02 ..
-rw------- 1 ubuntu ubuntu 391 May 25 2018 authorized_keys
Present working directory on Ubuntu:
ubuntu@ip-172-31-30-19:~/.ssh$ pwd
/home/ubuntu/.ssh
Contents of authorized_keys
file on the server:
ubuntu@ip-172-31-30-19:~/.ssh$ cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAA....0g1bMv+p11K8MDH sanjaydev
(contents are chopped off for privacy reasons)
Similarly, there is a known_hosts file on my local server:
Sanjays-iMac:.ssh sm$ cat known_hosts
54.251.104.13 ecdsa-sha2-nistp256 AAAAE2VjZHNhLX..Xsb/RBY=
52.76.85.25 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTI....hAkfLOc5g=
ec2-13-127-241-121.ap-south-1.compute.amazonaws.com,13.127.241.121 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXN....fu5Co4vYB0=
ec2-13-232-81-251.ap-south-1.compute.amazonaws.com,13.232.81.251 ecdsa-sha2-nistp256 AAAAE2VjZHNhL....nhNcRyfu5Co4vYB0=
35.154.168.85 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNo....NcRyfu5Co4vYB0=
13.126.30.42 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTIt....NcRyfu5Co4vYB0=
(contents are chopped off for privacy reasons)
Now my question is:
What should be equal to what?
I would think that the public key on the client should match with one of the entries inside the authorised_keys
file on the server and the public key of the server should match with one of the entres in the known_hosts
file on the client.
Unfortunately, when I manually try to match them they did not match fully (only first few characters match). It is important to note that the ssh connection still goes through without giving the -i <pemfile>
on the command line.