Introduction
++ This page is dedicated to advanced SSH usage examples. We will discuss the following concepts: +
-
+
- config files (for client) +
- tunneling +
- jumping +
From 76349f02e1c8eaa264c114632a18a70e9698a727 Mon Sep 17 00:00:00 2001
From: Artur BoryĆ
+ This page is dedicated to advanced SSH usage examples. We will discuss the following concepts:
+ SSH - Advanced Usage
+ Introduction
+
+
+
+ Config files allow you to specify certain rules for all or chosen hosts. The file has a really simple structure.
+ It is divided into sections which begin with the Host keyword. Sections are read one by one and the first
+ matching section takes precedence over the remaining sections - you write more specific sections at the top and the more general
+ sections below.
+
+ You might say that SSH client doesn't need any special configuration - you just type the user@host and that's it. + Well, what happens when you manage multiple servers? Maybe you want to use a different pair of keys for each servers? + Maybe the server uses a port other than the default 22 to avoid automated bots trying to log in? +
++ That's where config files come in handy! +
++ Let's assume that you manage 3 servers, with the following access info: +
+ You got tired having to always specify the identity file location with the -i option and the port with -p option for example2.com.
+ Don't even mention admin@very.long.hostname.example1.com!
+
In the given example, the config file could look like this:
+
+ Host server1
+ HostName very.long.hostname.example1.com
+ User admin
+ IdentityFile ~/.ssh/id_rsa
+
+Host server2
+ HostName example2.com
+ Port 2222
+ User billthemaster
+ IdentityFile ~/.ssh/example2_ecdsa
+
+Host server3
+ HostName 192.168.133.7
+ User management
+ IdentityFile ~/.ssh/id_rsa
+
+Host *
+ IdentityFile /path/to/some/other/key
+
You can see here usage of Host *. Options specified in this section will affect all other hosts.
+ SSH looks for the options in the following order: +
~/.ssh/config/etc/ssh/ssh_configYou can also specify a custom path with the -F argument, for example:
+
+ ssh -F ~/Documents/projects/someproject/config/ssh production
+ ...or discard any config file:
+
+ ssh -F /dev/null username@hostname
There's more to ssh config files, but I direct you to man ssh_config for more information