Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Simplify connections with SSH config files


    Learn how to use SSH config files to greatly simplify SSH connections to remote hosts, use hostname aliases, and set advanced directives such as Port and IdentityFile settings per host.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    Instructor: An SSH config file is a very elegant way to connect to an SSH server. This config file provides the ability to connect to SSH servers much more simply so you don't need to remember the intricate details surrounding an SSH connection. Let's create a file at ~/.ssh/config. SSH config files follow a very simple format. They start with a host directive, which is the host name you wish to use for this connection.

    Every other directive specified within the block is optional. It allows you to fine-tune the connection details if you wish. Let's indent the following lines four spaces, and add a hostname directive. This directive overrides the above host value, and allows you to use any alias you wish for the above host value. You can now SSHing into the remote host by typing ssh username@hostname, but instead of typing the entire hostname when SSHing into the server, just use the alias. This is so much easier to remember.

    Let's see if we can make it even simpler. Go back to your SSH config file and add a user directive. This is where you can define the user you wish to connect with. You can also specify the SSH key you wish to use for this connection by using an identity file directive followed by the location of your private key. This is useful if the SSH key you wish to use is different than the default SSH key on your machine.

    All directives here are optional, so you can pick and choose the ones you wish to use to customize this SSH connection such as specifying the port you wish to use. When all of your directives have been set, you can SSH using just the alias specified for the host directive. The SSH client will use the SSH config file to assign all of the directives specific to the SSH connection.