DEV Community

Mohit Kumar Yadav
Mohit Kumar Yadav

Posted on • Updated on

Set default SSH key for authenticate

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.

Top comments (0)