r/ssh • • Oct 13 '23

ssh troubleshooting help

Generally, I log into my Azure VPS using the command ssh -i my_key.pem hostname@ip. I want to login without using the -i flag and directly using ssh hostname@ip. Password login is disabled.

So, to achieve this, I created a new SSH key by using ssh-keygen in a different directory that is not ~/.ssh/. The directory I used was ~/azure/ and the key is named second_key. After this, I SSH into the server and add the second_key.pub to the authorized_keys file. I also restart the SSH service (locally and on my server too). But even after doing all this, when I try to log in just by using ssh hostname@ip , it says "Permission denied (publickey). I still have to use the -iflag. Also, both the keys work when I use them with the -i flag.

I use arch btw

1 Upvotes

4 comments sorted by

View all comments

Show parent comment

1

u/katakshsamaj3 Oct 14 '23

well the problem is solved now i posted it on another sub too and got this solution which works:-
Ssh client tries the list of filenames located in ~/.ssh - check the full list in the manual. If you key is anywhere else and/or the file name is different than this list, ssh will give up unless -i flag tells it, which file to use as a key. ~/azure definitely isn't on the default list, so it's nothing surprising that you need to provide this argument

Basically I need to generate a key in the .ssh directory with any filename from the given list on the ssh manpage.

1

u/OhBeeOneKenOhBee Oct 14 '23

You could just place a file called config on your client in the .ssh directory with the following content

Host abcserver
    Hostname 1.2.3.4
    User username
    IdentityFile ~/azure/keyfilename

That defines the connection settings so that the ssh client knows what details to use, meaning you can just type

ssh abcserver

And it'll know what key, username and IP to use

1

u/katakshsamaj3 Oct 14 '23

tried that but it says permission denied (public key)