From 76349f02e1c8eaa264c114632a18a70e9698a727 Mon Sep 17 00:00:00 2001 From: Artur Boryƛ Date: Fri, 9 Jul 2021 16:46:36 +0200 Subject: [sshadvanced] write intro and config files section --- sshadvanced.html | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 sshadvanced.html (limited to 'sshadvanced.html') diff --git a/sshadvanced.html b/sshadvanced.html new file mode 100644 index 0000000..33d9cb0 --- /dev/null +++ b/sshadvanced.html @@ -0,0 +1,131 @@ + + + + SSH - Advanced Usage – LandChad.net + + + + + + + +
+

SSH - Advanced Usage

+
+ +
+

Introduction

+

+ This page is dedicated to advanced SSH usage examples. We will discuss the following concepts: +

+

+

Config files

+

+ 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. +

+

Why even bother?

+

+ 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! +

+

Example scenario

+

+ Let's assume that you manage 3 servers, with the following access info: +

    +
  1. very.long.hostname.example1.com +
      +
    • user: admin
    • +
    • port: 22
    • +
    • key name: id_rsa
    • +
    +
  2. +
  3. example2.com +
      +
    • user: billthemaster
    • +
    • port: 2222
    • +
    • key name: example2_ecdsa
    • +
    +
  4. +
  5. 192.168.133.7 +
      +
    • user: management
    • +
    • port: 22
    • +
    • key name: id_rsa
    • +
    +
  6. +
+

+

+ 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.

+

But where do I put this file?

+

+ SSH looks for the options in the following order: +

    +
  1. command line arguments
  2. +
  3. ~/.ssh/config
  4. +
  5. /etc/ssh/ssh_config
  6. +
+

+

You 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

+
+ + \ No newline at end of file -- cgit v1.2.3