ssh tips and tricks

impress your friends and coworkers with these epic ssh tips !!!

ssh seems really easy to use, because it is. but could it be easier to use? let’s find out!

making config files

when using ssh, you might find yourself rewriting the same command over and over again, you could press the up arrow 100+ times to find the command that you were using the other day, or you could write a config file. your personal ssh config file is stored in ~/.ssh/config.
ssh config files have this stucture:

Host my_server
    <keyword> <value>
    <keyword> <value>
    <keyword> <value>
    <keyword> <value>
Host my_other_server
    <keyword> <value>
    <keyword> <value>
Host * # applied to all connections
    <keyword> <value>

as with most things, * represents a wildcard (i.e. 192.168.0.* will match everything from to and ? matches one character from 0-9 (i.e. 192.168.0.? will match everything from to you can read more about it in the ssh_config man page (man ssh_config). all possible keywords are also listed in the ssh_config man page.

okay! now, how can we apply this knowledge to something useful? let’s have an example.
say you’re trying to log in to as giovanni on port 24, you would use this command:

$ ssh -p 24

wow! what a pain to write! luckily we can use the config file to make this much more convenient to write. first, open up ~/.ssh/config using your favourite editor. now, we’ll define a host

Host site

now, let’s add some options

    User giovanni
    Port 24

hopefully, all those options should be fairly easy to understand, HostName is the host you want to connect to, User is the user you want to log in as and Port is the port you want to use. now, we’ll be left with this file

Host site
    User giovanni
    Port 24

finally, save it and test it out.

$ ssh site
Welcome to Ubuntu 20.04.2 LTS (GNU/Linux 5.4.0-51-generic x86_64)

 * Documentation:
 * Management:
 * Support:

  System information as of Sun Mar 14 00:03:14 UTC 2021

  System load:  0.0               Users logged in:       0
  Usage of /:   7.7% of 24.06GB   IPv4 address for eth0:
  Memory usage: 24%               IPv4 address for eth0:
  Swap usage:   0%                IPv4 address for eth1:
  Processes:    110

0 updates can be installed immediately.
0 of these updates are security updates.

*** System restart required ***
Last login: Sat Mar 13 18:07:30 2021 from

as you can see, ssh has seen our config and used it to fill in all the details for us, which has saved us a few frames that we can use later on. this is only the tip of the iceberg (well, more like the middle of the iceberg, there aren’t that many things you can do with you ssh config file), go search up some examples on the internet and enjoy the extra seconds of your life not spent typing in ssh commands.

this article was lovingly written by cark and was last updated 2021-03-13
← go back
↜ back to wiki root
↞ go to the homepage