SSH Config for quickly server access

SSH is very powerful and required tools for any servers. But the more servers we have, the harder we have to remember the IP, the hostname or maybe where the key file is. SSH Config is a place to manage all these mess. Let’s start

In your home folder, with Linux / MacOS is alway cd ~ to come home. Make a directory named .ssh if it’s not exist.

In side ~/.ssh folder, please creating a file named config. This is the place where all SSH config will be laid


Host <easy remember name for a server>
   Hostname <actual server hostname or IP Address>
   User <name of user has privileges to access this server>
   IdentityFile <full path to private key file that used to access this server>
   Port <if server has access with strange port, by default, it's port 22


For simple server

Host mymagestore-prod
    User ubuntu
    IdentityFile /home/ubuntu/.ssh/mymagestore.pem

For Github / Gitlab SSH Key

    User git
    IdentityFile /home/ubuntu/.ssh/github.priv

Special Options

We can define the common config that will affect to all host config in this file

Host *
    IdentitiesOnly yes # Useful with hosts have brute-force protection
    PubkeyAuthentication yes # Force using key for access
1 Like