Index ¦ Archives ¦ Atom

Using ssh config to save settings and make your life easier

SSH is an amazing tool, I use it all the time and not just for logging into remote computers, but also to create tunnels, copy files and access git repositories.

But I don't want to have to remember fidily commands something like ssh I2P_Router is so much nicer than something like

ssh -i .ssh/Michael-Van-Delft.id_rsa -L 7657:localhost:7657 -L 4444:localhost:4444 -L 6668:localhost:6668 i2p_user@example.com:2233

I keep my ~/.ssh folder synced as a git repository, that I sync over https with gogs. For all other git repositories I use ssh, but https solves the bootstap problem where I setup a new computer and want to download my ssh settings.

Below is an example of my ~/.ssh/config file with just a few changes.

# Override /etc/ssh_config
# This is a potential issue where someone who can read your ~/.ssh/known_hosts
# can see what servers you have SSHed into. However I'm not concerned by that.
# It makes it much easier to just delete one line from known_hosts when a
# server changes key.

HashKnownHosts no

###############################################################################
# Servers                                                                     #
###############################################################################
Host example.com www.example.com brand.example.com
    IdentityFile ~/.ssh/Michael-Van-Delft.id_rsa
    User michael

# Port forwarding for I2P. Simply run `ssh I2P_Router`
# then browse to http://localhost:7657/
Host I2P_Router
    HostName example.net
    IdentityFile ~/.ssh/Michael-Van-Delft.id_rsa
    User i2p_user
    LocalForward 7657 localhost:7657
    LocalForward 4444 localhost:4444
    LocalForward 6668 localhost:6668

# Example of a local server with IPv6 only
Host zilean
    IdentityFile ~/.ssh/pi@zilean.example.com.id_rsa
    User pi
    AddressFamily inet6
    HostName 2001:0db8:6101:cc01::7

###############################################################################
# Git and Service accounts                                                    #
###############################################################################
Host github.com
    HostName github.com
    IdentityFile ~/.ssh/git@github.com.id_rsa
    User git
    IdentitiesOnly yes

# This is good if you have a server you ssh into (like example.com from the top
# entry) where you want to use diffrent credentials for git as you do when you
# SSH in normaly.
#
# To clone a repository simply run
# git clone gogs:Michael/exotic-security.git
Host gogs
     HostName example.com
     IdentityFile ~/.ssh/gogs.id_ed25519
     User git
     IdentitiesOnly yes

Creative Commons License
Content on this site is licensed under a Creative Commons Attribution 4.0 International License.
Built using Pelican. Based on a theme by Giulio Fidente on github.