ssh application is essential to just about everyone.
Are you using it as efficiently as possible?
Check out these tips and config settings that will make your life easier,
including aliases, specifying identify files, forwarding ports, and
using jump hosts.
We will assume you already have OpenSSH installed. It comes installed by default with most Linux distributions. If you are using Windows, try Windows Subsystem for Linux.
Also, check out my
issh tool for a convenient SSH menu with a curses TUI: https://github.com/DevDungeon/issh.
SSH has a lot of potential options:
ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec] [-D [bind_address:]port] [-E log_file] [-e escape_char] [-F configfile] [-I pkcs11] [-i identity_file] [-J [[email protected]]host[:port]] [-L address] [-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address] [-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]] [[email protected]]hostname [command]
Some simple usage example uses may include:
ssh devdungeon.com ssh [email protected] ssh -p 2222 -i ~/.ssh/custom_id_rsa devdungeon.com
It can be tedious to configure all of the options using command-line flags, so the SSH config file allows you to set settings for different hosts and access them using a convenient alias.
In the SSH config file you can configure aliases to use.
For example, if we set up an alias for host
we could simply connect using:
We will look at an example configuration in the next section.
SSH config file template
# Example ~/.ssh/config # Connect using ``ssh sandbox`` or ``scp sandbox:* .`` Host sandbox HostName sandbox.local User myusername IdentityFile ~/.ssh/id_rsa Port 22 ServerAliveInternal 30 ProxyJump jumphost.local # If using local forward, do ssh -f -N host # -f puts ssh in background # -N makes it not execute a remote command LocalForward 9906 127.0.0.1:3306 # Another local forward example. # This one will take the service that sits on the remote host # listening locally on port 3006 and makes it available # via a local listener that listens on localhost:9999. # E.g. Make a remote database that only listens locally available # on your localhost port 9999 LocalForward 127.0.0.1:9999 127.0.0.1:3306 # Remote forward will make something available on the local # machine/network available to the remote server. # E.g. Making an internal git server available to the host you are # connecting to that would not normally be able to reach the git # server. This eample makes git available on the remote server's port 9999 while on # the remote SSH server # In the SSHD config set GatewayPorts to yes to allow public access RemoteForward 9999 locally-accessible-address:22 # Set up a SOCKS proxy on 127.0.0.1:9999 that lets you pivot through the remote host(HostName) # Then configure the local tool/browser to use a SOCKS proxy of localhost:9999 DynamicForward 127.0.0.1:9999 Host myotherhostalias HostName example.com # This will apply to all hosts. Host * IPQoS=throughput
Connecting through jump hosts
SSH through jump host with the
ssh -J myjumpserver destinationserver
SCP through jump host with the
-o ProxyJump option:
scp -o ProxyJump=myjumphost <source> <dest> scp -o ProxyJump=myjumphost devdungeon.com:file.txt .
You can reference aliases in the ProxyJump settings that are defined in the SSH config file, or specify it literally.
You should now have a solid grasp on how to configure your SSH client for extra convenience.