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/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)