3.1 KiB
title | subtitle | author | date |
---|---|---|---|
ssh tips and tricks | impress your friends and coworkers with these epic ssh tips !!! | cark | 2021-03-13 |
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 192.168.0.0
to 192.168.0.255
) and ?
matches one character from 0-9 (i.e. 192.168.0.?
will match everything from 192.168.0.0
to 192.168.0.9
). 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 cark.website
as giovanni
on port 24
, you would use this command:
$ ssh giovanni@cark.website -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
HostName cark.website
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
HostName cark.website
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: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
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: 128.62.125.163
Memory usage: 24% IPv4 address for eth0: 10.16.0.6
Swap usage: 0% IPv4 address for eth1: 10.106.0.3
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 91.110.54.64
giovanni@cark:~$
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.