Caleb X. Berger / c-x-berger
Topics covered in CS 193 SSH 101:
scp
scp
reviewFrom | To | Command |
---|---|---|
Local | Remote | scp file user@remote:~/dest/dir |
Remote | Local | scp user@remote:~/source/file ~/local/copy.txt |
You can recursively copy entire directories with the -r
flag
Topics covered here:
man ssh-keygen
will tell you there are four key types
You know, like a liar.
Practically, three work for most hosts:
ecdsa
rsa
ed25519
dsa
has systemic flaws that can leak the private key - yikes!
RSA will work on everything, but requires big keys
Ed25519 is the favorite child - short keys, doesn't have DSA's issues... but it's new enough that some Purdue machines don't support it
Like RHEL 6 machines in the ECN.
Hail Purdue.
Map a port on one machine to another
Make remote services available at local addresses, or vice versa
Honestly? Usually, to bypass a firewall.
ssh -L 123:localhost:456 fred@example.org
routes traffic bound for localhost:123
to
example.org:456
via example.org
Traffic can also pass through the remote to an even
further host: -L 8000:example.com:443 example.org
You probably want to add -fNT
to be "nicer"
ssh -fNT -L localport:destination:port user@viahost
Many hosts read e.g. the HTTP Host
header
and either block or act very strangely when they see an
unexpected value
We will see a way around this later
ssh -R 123:localhost:456 fred@example.org
sends traffic from example.org:123
to localhost:456
Ask a remote to forward traffic to you (or through you, anyway)
ssh -fNT -R srcport:destination:destport user@srchost
We saw that some services freak out when tunneled to
SOCKS is a way of forwarding that's actually meant to be a proxy. As such, the application (e.g. your browser) has to support it
ssh -D 1337 -fCNT fred@example.org
Sign SSH keys with some given "master key"
A host can authorize any keys signed by some root certificate for authentication, and clients may choose to trust host keys signed by some root.
Useful within organizations to reduce friction with new keys/hosts
This will later sign our host and user keys
ssh-keygen -t ed25519 -f example-ca -C "Comment"
Keep example-ca
well-secured!
example-ca.pub
should go to wherever
you intend to trust signed keys.
Just be sure to set keysize on RSA keys.
ssh-keygen -s example-ca \
-n your,usernames \
-V +52w \
-I logging-name \
key.pub
example-ca.pub
on the hostsshd_config
, add a line
TrustedUserCAKeys /path/to/example-ca.pub
example-ca
is
allowed for the user(s) in that key's principals list.
In our example, that would be your,usernames
-h
in there.
ssh-keygen -h -s example-ca \
-n host.example.com \
-V +52w \
-I host.name-key \
keyfile.pub
Add HostCertificate /path/to/keyfile-cert.pub
to sshd_config
@cert-authority *.purdue.edu ssh-ed25519 ...
Add @cert-authority some,hosts XXX
to
known_hosts
where XXX
is the
contents of example-ca.pub
Speed up SSH by only logging in once
Specifically, after first login TCP/IP connection is kept open for a set time after exit.
And "all" we have to to is edit ~/.ssh/config
Example multiplexing configuration:
Host *.cs.purdue.edu
# user@host:port
ControlPath ~/.ssh/controls/%r@%h:%p
# use master connection iff available
ControlMaster auto
# keep master connection alive for 10 minutes after last session ends
ControlPersist 10m
Options like -L
, -R
will add a new forward, but it won't close until the master closes as well
We also can't change forwarded ports on the fly
To cancel a forward on a master connection, use ssh -O cancel -L ... user@host
Special key sequences that instruct SSH to do particular things "mid-flight"
These are used during a session to alter that session.
Some are client-side only, not dependent on host
Press, in order, one at a time, Enter, ~, ?
Examples:
~.
kills that session and all multiplexed sessions~C
is really interesting (the "SSH command-line") but is unavailable on multiplexed~V
/~v
increases/decreases SSS's verbosityThese slides are on GitHub at https://github.com/c-x-berger/ssh-201
The slide deck is also served as a GitHub pages site.