Set default SSH key for authenticate

mohitkyadav

Mohit Kumar Yadav

Posted on March 22, 2021

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.

💖 💪 🙅 🚩
mohitkyadav
Mohit Kumar Yadav

Posted on March 22, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related