DEV Community

loading...

How to authenticate with ssh without mentioning private key each time

mohitkyadav profile image Mohit Kumar Yadav ・1 min read

Navigate to ~/.ssh and if using Windows and git bash go to C:\Users\<user>\.ssh

Create a file named config in following format

Host *.someurl.com
IdentityFile ~/.ssh/my_key
Enter fullscreen mode Exit fullscreen mode

In this example * (star) is for everything. Now to connect do ssh ubuntu@abc.someurl.com.

Some more examples of ssh config file.


Host someurl.com
IdentityFile <path to private key>

Host <ip address>
IdentityFile <path to private key>
Enter fullscreen mode Exit fullscreen mode

You can further define config to save time connecting to machines

Host dev
        HostName dev.mysite.com
        IdentityFile <path to private key>
        User ubuntu

Host stage
        HostName stage.mysite.com
        IdentityFile <path to private key>
        User <username>             
Enter fullscreen mode Exit fullscreen mode

And directly connect with ssh dev or ssh stage.

Discussion (0)

pic
Editor guide