If you use OpenSSH to connect to SSH servers on a regular basis, you may benefit from using an SSH configuration file. This will help you to shorten long commands:
ssh -p 2222 alykhan@student.cs.uwaterloo.ca
into an easily customizable shortcut:
ssh cs
This is accomplished by creating a text file located at ~/.ssh/config
on your local machine with a few pieces of information and ensuring a specific set of permissions are applied to that file.
Setup Instructions
- Make the
~/.ssh/
directory if it does not already exist:
mkdir ~/.ssh/
- Set the permissions for the
~/.ssh/
directory such that it is readable, writeable, and executable for only the current user (i.e.rwx------
):
chmod 700 ~/.ssh/
- Create a text file at
~/.ssh/config
following this example format:
Host cs
HostName student.cs.uwaterloo.ca
User alykhan
Port 2222
Note that this file must also meet specific permissions requirements as specified by the ssh_config
man page (i.e. rw-------
):
~/.ssh/config
— Because of the potential for abuse, this file must have strict permissions: read/write for the user, and not accessible by others.
chmod 600 ~/.ssh/config
Usage
Congratulations! You may now connect to the SSH host via:
ssh cs
Feel free to add multiple Host
entries to the config
file, to have quick access to different HostNames
via shortcuts like ssh website
, ssh work
, etc. Each of these entries may also have different User
, Port
, and other configuration values.