by m463 · 6y ago · 0 comments
Host x
Hostname full.host.name.com (or 1.2.3.4)
User <myuser>
IdentitiesOnly yes
IdentityFile ~/.ssh/id_x_ed25519
I give hosts short names so you can `ssh x`to do automatic login, I generate identities for some machines
ssh-keygen -t ed25519 -f ~/.ssh/id_x_ed25519
use ssh-copy-id to copy the identity to the target machine so it lets you in: ssh-copy-id -i ~/.ssh/id_x_ed25519.pub x
or if your machine doesn't have ssh-copy-id (older macs); cat ~/.ssh/id_x_ed25519.pub | ssh x "cat >> .ssh/authorized_keys"
IdentitiesOnly means it will only send that one identity for that one machine (otherwise it will try all of them, like a janitor trying to open a locker with a big keychain of identical keys)If you always want to use a password to log into a machine, but want to be able to log in in other windows to the same machine without a password:
Host x
...
ControlMaster auto
ControlPath ~/.ssh/master-%r@%h:%p
this will multiplex all activity to that host through one tcp connectionyou can also use Host * at the beginning of your config to do this for all hosts
to tunnel vnc over ssh to a remote mac(I do this with mac)
Host foo
...
LocalFoward 5900 localhost:5900
ssh foo
then locally vnc to localhost:127.0.0.1edit: a typo
alias ssh-MasterConnection-check="ssh -O check " alias ssh-MasterConnection-exit="ssh -O exit "
+ then you use them as 'ssh-MasterConnection-check host' etc.
It seems to me like the session persistence tmux gives would be worthwhile if you have a lot of simultaneous sessions going.
scp remote:~/err[tab] .[enter]
Also, bastion connections get multiplexed as well so connecting to multiple different hosts behind the bastion goes faster.
ssh x
then in other windows, I do things like this: scp file x:
ssh x command
rsync from/ x:to/
emacs /ssh:x:filename (this is tramp mode)
edit: one more thing ssh x -o BatchMode=yes command
if you have an automatic script to run on a remote machine, adding BatchMode=yes will make it error out instead of stopping and asking for a passwordHaving multiple windows vs tabs on my desktop seems so much easier.
From what I gather, tmux is useful if you are basically running a persistent remote workspace via terminal on a server and treat your desktop like a thin-client, is that correct?
If the bad guys get a copy of my public key off one remote server, they can't use it to access any other remote server. They would need the private key, which is on my laptop.
And if the bad guys get my laptop, then they get all my keys; having separate private keys for separate servers doesn't help if they're all sitting next to each other on one device.
I do set a password on my private key, though.
See also: https://github.com/FiloSottile/whoami.filippo.io
Using a private key per system or set of systems means that such an attacker would only gain access to what that key grants them access to.
My "github" key only grants access to my github repos, not to my bitbucket repos or to my DigitalOcean servers, or my Scaleway servers.
I have an SSH key for each "thing", and each key is kept in a different keyring via https://github.com/ccontavalli/ssh-ident, _precisely_ to avoid that problem.
As an example, an attacker gaining root on my Oracle Cloud free server will not be able to clone all my Github repos with it: I only use that key to connect to that server, and while I may have the github key unlocked at the same time - that's on a different keyring which the server has no visibility of.
I have, since 2010, practiced "jumps" only - that is, if I need to connect to a non-routeable host through a routeable one ("bastion host" or "jump host"), then the intermediate host is only used as a transport, by way of -L/-R forwarding of the final destination's ssh port, or by netcat, or (since a couple of years ago) SSH's internal ProxyJump or ProxyCommand; compared to agent forwarding, this is less efficient CPU-wise and traffic-wise, but not by much; and it is as safe as connecting to the final destination directly, unlike agent forwarding.
1. I still have a need to "for s in $list_of_servers; ssh -A $s '..'; done"
How many times do I have to push the button? Is there a setting that allows that "push to allow" for a short while? Great, if so:
2) when I ssh into a system and touch the button to allow it, and the push allowed the use of they key for a short while, am I not in the same problem as before - as the system may be compromised and may be performing other operations I'm unawares of?
A solution for this would be to have multiple hardware keys for things I manage: one for $work, one for $personal, another for $github, etc. etc. but then managing them and - especially!! - their SSH agent which may be in memory but relies on the hardware being present, with all issues _that_ entails.... becomes a frigging mess.
So I'm torn... between the simplicity of a hardware key with push-to-allow... and actually being able to _use_ it _securely_.
https://github.com/ccontavalli/ssh-ident is what I use to manage those agents - one agent per key.
> Specifies the number of bits in the key to create. For RSA keys, the minimum size is 1024 bits and the default is 2048 bits. Generally, 2048 bits is considered sufficient. DSA keys must be exactly 1024 bits as specified by FIPS 186-2. For ECDSA keys, the -b flag determines the key length by selecting from one of three elliptic curve sizes: 256, 384 or 521 bits. Attempting to use bit lengths other than these three values for ECDSA keys will fail. Ed25519 keys have a fixed length and the -b flag will be ignored.
ssh-copy-id -i ~/.ssh/id_x_ed25519.pub x
Thanks for mentioning this - I've been SSH'ing for a long time and never run across it.