DEV Community

Niklas
Niklas

Posted on • Originally published at niklasmtj.de

Configure SSH for a specific Host

I had to set up an Ubuntu machine a couple weeks back and set up a fresh git server at work. To get rid of the authentication every single push and pull I set up ssh keys to authenticate that way.

Example

With the following ssh-config the ssh client will open a ssh connection with only typing ssh example. The user that is used then is niklas. Otherwise you would have to write ssh -i ~/.ssh/example.key niklas@example.com. If this is a connection you have to connect to more often this is can be a waste of effort. Just simply open your ssh-config with nano ~/.ssh/config and use the following config:

Host example
    HostName example.com
    User niklas
    IdentityFile ~/.ssh/example.key

Copy specific key with ssh-copy-id

$ ssh-copy-id -i path/to/key user@host

This command will easily transfer your public key to the authorized_keys on your server.

Thanks for your time,
Niklas

Top comments (0)