February 23, 2015

Using the SSH Config File

^ Ad space. I gotta pay the bills!

Make SSH easy by adding entries to your local SSH config file. From this file we can set useful defaults to make logging into remote servers as easy as ssh myserver.In the previous video, we used this long command to login with a newly created SSH key:

ssh -o "IdentitiesOnly yes" \
    -i "/Users/fideloper/.ssh/id_sshex" root@104.236.90.57

Locally on my Mac, I can create/edit an ssh config file:

vim ~/.ssh/config

Add the following to mirror our long command:

Host ssh-ex
    HostName 104.236.90.57
    User root
    Port 22
    IdentitiesOnly yes
    IdentityFile ~/.ssh/id_sshex

Save and exit that file, and try to login in our simpler way:

# Should work:
ssh ssh-ex

We can use this with any SSH-based tool:

# For example, scp:
scp -r ~/Downloads ssh-ex:/path/to/files

# Or a one-off command, list home directory
# on remote server:
ssh ssh-ex ls -lah

See the man page of ssh to check out all the options you can use in the config file.

man ssh

All Topics