(gs):Create SSH config file

  • This page was last modified on February 7, 2011, at 15:16.
The (mt) Community Wiki is a collaborative project. Any (mt) Media Temple customer or employee may contribute. Not all articles and/or content have been tested for accuracy by (mt) Media Temple.

For officially moderated and tested articles, be sure to visit our KnowledgeBase.

From (mt) Community Wiki

Contents


By creating a local configuration file for ssh you can create shortcuts for servers you frequently access, in addition to configuring more advanced options. For the purposes of this article we will show you how to create a shortcut for a (gs) Grid-Service and (dv) Dedicated-Virtual Server, including how to keep your connection active.

This article has the following dependencies:

  • Please make sure you have a basic understanding of SSH and have SSH access enabled. See (gs):SSH connection
  • example.com is used as an example. Please be sure to replace this text with the proper information for your site or server.
  • This article assumes that you are using a Unix operating system, such as OS X or Ubuntu. We will use OS X as our example. Please modify as needed for your environment.

1. Launch the terminal application on your local computer and create your config file in your home directory:

On OS X this is located at /Applications/Utilities/Terminal.app. Consider dragging this application into your Dock for convenience.

touch /Users/username/.ssh/config

Your .ssh directory is automatically created when you use the ssh command for the first time. If you have never used ssh before under this user account please create the directory first using:

mkdir /Users/username/.ssh && chmod 700 /Users/username/.ssh

2. Edit the file using vi or any Unix text editor you are comfortable with. We will use vi:

vi /Users/username/.ssh/config

3. There are many options for your config file. Below is an example for creating a shortcut to your (gs) Grid-Service:


Host grid

HostName example.com
User serveradmin@example.com

4. Now that you have your shortcut created you can add even more options directly below these entries. For instance maybe you want to make sure your session "stays alive" while you step away from your keyboard for a bit. The following example will refresh your connection every 30 seconds for a maximum of one hour:

ServerAliveInterval 30
ServerAliveCountMax 120

5. Perhaps you have both a (gs) and a (dv) service with us. Here is an example file showing multiple hosts:

Host dv

HostName dv.example.com
User ftpuser
ServerAliveInterval 30
ServerAliveCountMax 120

Host grid

HostName grid.example.com
User serveradmin@grid.example.com
ServerAliveInterval 30
ServerAliveCountMax 120


Notes/Supplemental Resources:

  • Running the command "man ssh_config" in a Terminal will show you detailed usage information.
  • [http://www.openssh.com/manual.html OpenSSH homepage, including a section on ssh_config