-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssh.txt
89 lines (71 loc) · 5.38 KB
/
ssh.txt
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
\e[38;5;201m--- SSH ---\e[0m
-n does something with /dev/null and stdin, making ssh work in a while loop. for loops don't need this.
-A: agent forwarding: your ssh keys are now available to SSH on the remote host as well
-G foo: get all settings for host foo from the .ssh/config file (and a shitton more, | less for finding things)
-t "Force pseudo-terminal allocation". makes the remote host think you have a terminal, so screen-based programs
(and cron-vs-interactive checks...) might work better. Also allows for \e[38;5;208mssh -t host sudo -i\e[0m to jump straight to root
with a proper environment (sans -t you have missing TERM and PS1).
-o BUNCH of options, check \e[38;5;208mman ssh_config\e[0m for the list. Useful ones:
\e[38;5;208m-o batchmode=yes\e[0m that makes it run non-interactively, and will not ask for input like password of confirm hostkey changes.
\e[38;5;208m-o SendEnv=<VarName>\e[0m send/copy/export the local env variable to the remote's Env. This can be useful to conditionally run
some remote ~/.bashrc things based on the origin of the session.
\e[38;5;201mNB:\e[0m the variable name needs to be specifically allowed in the remote's \e[38;5;226m/etc/ssh/sshd_config\e[0m using
\e[38;5;208mAcceptEnv <VarName>\e[0m (multiple delimited by space). \e[4;1mMake sure\e[0m this config line sits above any match blocks!
\e[38;5;208m-o SetEnv=<VarName>=<value>\e[0m like the above except you can set a new/different one, since \e[38;5;208mOpenSSH 7.8\e[0m
-vvv 1 to 3 v's for debugging non-cooperative connections
# To give multiple commands to be run remotely over ssh, quote the lot, or escape the \; thing between them
# Completely randomly, you can add newlines to files by doing \e[38;5;208mecho >> foo.txt\e[0m
# Mind you, still have to quote the >> or the whole thing when ssh'ing the command.
# SSH defines some escapes you can use while in session, they all start with a tilde '~', which is only
# interpreted as special when following a newline. \e[38;5;208m~?\e[0m gets you a list, \e[38;5;208mman ssh\e[0m has longer explanations under
# \e[38;5;201mESCAPE CHARACTERS\e[0m. Some useful ones:
~. # disconnect (presumably when some remote process hangs on you)
~& # "Background ssh at logout when waiting for forwarded connection / X11 sessions to terminate."
Verbose debugging -v to -vvv, output is prefixed with debug1 to debug3.
The client/server send number or typed packets, here is what the numbers mean:
https://www.rfc-editor.org/rfc/rfc4250.html#section-4.1.2
\e[31mSSH protocol v.1 is no longer supported\e[0m
# this can mean you need to use a capital P for port if you're using a lowercase p. It can also mean you
# need to use a lowercase p for port if you're using a capital P. Don't ask.
\e[38;5;201m--- SSH-KEYGEN ---\e[0m
### remove a passphrase
$ ssh-keygen -p
# then simply enter the old passphrase and leave the new one blank
### Do this public and private key even belong together?
$ ssh-keygen -E md5 -lf ~/.ssh/id_rsa
$ ssh-keygen -E md5 -lf ~/.ssh/id_rsa.pub
# should return the same results
### Create public key from private key
$ ssh-keygen -y -f foobar > foobar.pub
# -y outputs the public key, -f foobar specifies the private file. Etc.
# see also \e[38;5;201mssh-agent\e[0m
\e[38;5;201m--- SSHD ---\e[0m
# Check /etc/ssh/sshd_config syntax before restarting the service:
$ sshd -t
# You can add match blocks to /etc/ssh/sshd_config to define specific source IPs or authentication methods for users,
# but they're finicky in that if the global settings allow them, the match blocks are ignored.
# To allow a specific user only from specific IP addresses, just edit its \e[38;5;226m.ssh/authorized_keys\e[0m file:
from="192.168.0.*" ssh-rsa AAAAB3NzaC1yc2E...
# it should allow multiple comma-separated addresses and wildcards
\e[38;5;201m--- TUNNELLING ---\e[0m
### Create a secure tunnel to a specific port on a remote host (example given for VNC)
$ ssh -L \e[32;1m5900\e[0m:\e[38;5;208mlocalhost:5900\e[0m username@remote_host
# \e[37;1m-L\e[0m for local port forwarding
# \e[32;1m5900\e[0m refers to the port on the client (your localhost)
# \e[38;5;208mlocalhost:5900\e[0m refers to port 5900 on the \e[1mlocalhost of the remote host\e[0m, ie it's not going to another host on the remote
# network. Now you connect your VNC client to localhost:\e[32;1m5900\e[0m and SSH will shuffle it to the remote listener's port.
### SOCKS Proxy to browse from another host
$ ssh -D 8080 username@remote_host
# Go to manual proxy configuration in your browser settings -> network
# In the SOCKS Host field, enter localhost and port 8080 (or whatever port you chose).
# Select SOCKS v5 (which supports DNS over the proxy).
# Check Proxy DNS when using SOCKS v5 to make sure all DNS requests are also routed through the remote server.
### Reverse SSH tunnel
# on the target box (Alice), create a reverse tunnel that connects the remote port 2222 to local 22:
Alice_$ ssh \e[32;1m-R 2222:localhost:22\e[0m bob@remote
# keep this connection active, don't let the computer sleep/lock while you're away
# Now on the remote (Bob's machine), you can simply connect to \e[38;5;208m-p 2222 alice@localhost\e[0m:
Bob_$ ssh -p 2222 alice@localhost
# If both Alice and Bob are behind a firewall/router, you can use a jumphost provided both can access that:
Alice_$ ssh -R 2222:localhost:22 \e[32;1mcarol@jumphost\e[0m
Bob_$ ssh \e[32;1m-J carol@jumphost\e[0m -p 2222 alice@localhost