blob: 33d9cb04904fe056770b563e171a5ab481c40138 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
<!DOCTYPE html>
<html lang=en>
<head>
<title>SSH - Advanced Usage – LandChad.net</title>
<meta charset="utf-8" />
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel='stylesheet' type='text/css' href='style.css'>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel='alternate' type='application/rss+xml' title='Land Chad RSS' href='/rss.xml'>
</head>
<body>
<header>
<h1>SSH - Advanced Usage</h1>
</header>
<nav></nav>
<main>
<h2>Introduction</h2>
<p>
This page is dedicated to advanced SSH usage examples. We will discuss the following concepts:
<ul>
<li>config files (for client)</li>
<li>tunneling</li>
<li>jumping</li>
</ul>
</p>
<h2>Config files</h2>
<p>
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 <code>Host</code> keyword. Sections are read one by one and <b>the first
matching section takes precedence over the remaining sections</b> - you write more specific sections at the top and the more general
sections below.
</p>
<h3>Why even bother?</h3>
<p>
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?
</p>
<p>
That's where config files come in handy!
</p>
<h3>Example scenario</h3>
<p>
Let's assume that you manage 3 servers, with the following access info:
<ol>
<li>very.long.hostname.example1.com
<ul>
<li>user: admin</li>
<li>port: 22</li>
<li>key name: id_rsa</li>
</ul>
</li>
<li>example2.com
<ul>
<li>user: billthemaster</li>
<li>port: 2222</li>
<li>key name: example2_ecdsa</li>
</ul>
</li>
<li>192.168.133.7
<ul>
<li>user: management</li>
<li>port: 22</li>
<li>key name: id_rsa</li>
</ul>
</li>
</ol>
</p>
<p>
You got tired having to always specify the identity file location with the <code>-i</code> option and the port with <code>-p</code> option for example2.com.
Don't even mention <code>admin@very.long.hostname.example1.com</code>!
</p>
<p>In the given example, the config file could look like this:
<code><pre>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
</pre></code>
</p>
<p>You can see here usage of <code>Host *</code>. Options specified in this section will affect all other hosts.</p>
<h3>But where do I put this file?</h3>
<p>
SSH looks for the options in the following order:
<ol>
<li>command line arguments</li>
<li><code>~/.ssh/config</code></li>
<li><code>/etc/ssh/ssh_config</code></li>
</ol>
</p>
<p>You can also specify a custom path with the <code>-F</code> argument, for example:
<code><pre>ssh -F ~/Documents/projects/someproject/config/ssh production</pre></code>
</p>
<p>
...or discard any config file:
<code><pre>ssh -F /dev/null username@hostname</pre></code>
</p>
<p>There's more to ssh config files, but I direct you to <code>man ssh_config</code> for more information</p>
</main>
<footer>
<a href="https://landchad.net">LandChad.net</a>
</br>Because Everyone should be an Internet LandChad.</br>
<a href="index.html">
<li><img src="pix/chad.gif" alt="chad"></li>
</a>
<a href="rss.xml">
<li><img src="pix/rss.svg" alt="RSS"></li>
</a>
<a href="pix/btc.png">
<li><img src="pix/btc.svg" alt="BTC"></li>
</a>
<a href="pix/xmr.png">
<li><img src="pix/xmr.svg" alt="XMR"></li>
</a>
<a href="https://github.com/lukesmithxyz/landchad">
<li><img src="pix/git.svg" alt="Github"></li>
</a></footer>
</body>
|