From 44a565438f47c8d3296bad1f4e48c4ba430eb217 Mon Sep 17 00:00:00 2001
From: Artur BoryĆ to
---
sshadvanced.html | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
(limited to 'sshadvanced.html')
diff --git a/sshadvanced.html b/sshadvanced.html
index 563b737..e825f45 100644
--- a/sshadvanced.html
+++ b/sshadvanced.html
@@ -71,7 +71,7 @@
Don't even mention admin@very.long.hostname.example1.com!
In the given example, the config file could look like this:
-
+
Host server1
+
Host server1
HostName very.long.hostname.example1.com
User admin
IdentityFile ~/.ssh/id_rsa
@@ -89,7 +89,7 @@ Host server3
Host *
IdentityFile /path/to/some/other/key
-
You can see here usage of Host *. Options specified in this section will affect all other hosts.
You can also specify a custom path with the -F argument, for example:
-
+ ssh -F ~/Documents/projects/someproject/config/ssh production
ssh -F ~/Documents/projects/someproject/config/ssh production
...or discard any config file:
-
+ ssh -F /dev/null username@hostname
ssh -F /dev/null username@hostname
There's more to ssh config files, but I direct you to man ssh_config for more information
-L option.
Let's say you want to access a MySQL service on the remote server. You can tell SSH to route any
traffic that comes to your 3000 port to port 3306 on the remote server with the following example:
- ssh -L 3000:localhost:3306 username@example.com
+ ssh -L 3000:localhost:3306 username@example.com
The above command states that anyone connecting to your port 3000 will be routed via the SSH connection to the localhost:3306 from the remote server's perspective
If you can't understand the above description, let's take a look at another example:
-
+ ssh -L localhost:8080:192.168.178.25:80 username@example.com
ssh -L localhost:8080:192.168.178.25:80 username@example.com
The above command states that any traffic coming from your device (and only yours, because of localhost) will be routed via the
@@ -138,7 +138,7 @@ Host *
In general, the argument's structure is as follows:
-
+ -L [local_address:][local_port]:[remote_address]:[remote_port]
-L [local_address:][local_port]:[remote_address]:[remote_port]
The local_address can be your LAN IP, localhost or any other address that your device has. Depending on it, other devices in
@@ -148,7 +148,7 @@ Host *
The remote_address can be any address reachable from the server.
You can, of course, route multiple ports. For example:
-
+ ssh -L 8000:localhost:8000 -L 8001:localhost:8001 username@example.com
ssh -L 8000:localhost:8000 -L 8001:localhost:8001 username@example.com
Please, remember, this works only on TCP based services, not UDP based.
@@ -167,16 +167,16 @@ Host *
edit /etc/ssh/sshd_config file, to instruct SSH server to route traffic to the other end of SSH connection - your device.
Find and uncomment or append the one of the following lines to the file:
-
+
GatewayPorts yes # to allow all remote devices
+
GatewayPorts yes # to allow all remote devices
GatewayPorts clientspecified # to allow only specific remote devices
-
You can then specify the forwarding rule with the -R option, for example open 192.168.178.2:21 on your local network,
to be accessible from a remote server on port 2100:
-
+ ssh -R 2100:localhost:21 username@example.com
ssh -R 2100:localhost:21 username@example.com
...or provide access only to your friend with an IP 111.111.111.111:
- ssh -R 111.111.111.111:2100:localhost:21 username@example.com
ssh -R 111.111.111.111:2100:localhost:21 username@example.com
You can replace localhost with any host accessible from your local device, for example your local media server etc.
You can easily jump as shown in the following example:
-
+ ssh -J username1@example1.com username2@example2.com
ssh -J username1@example1.com username2@example2.com
You can also specify multiple intermediaries, by separating them with a comma:
-
+ ssh -J username1@example2.com,username2@example.com username3@example3.com
ssh -J username1@example2.com,username2@example.com username3@example3.com
There is also a possibility to set up "jumping" connection in a config file:
-
+
Host intermediary1
+
Host intermediary1
HostName target.intermediary-example.com
User john
@@ -204,7 +204,7 @@ Host target1
Host target2
HostName target2.example.com
ProxyJump username@example1.com
-