5 ms·
I always create and heavily use ~/.ssh/config Host x Hostname full.host.name.com (or 1.2.3.4) User <myuser> IdentitiesOnly yes
by m463 7y ago
I always create and heavily use ~/.ssh/config
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 connection
you 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.1
- 3r8riacz 7y agoDoesn't ed25519 keys are fixed to 256 in terms of the -b flag, so no need to specify there anything?
- jstanley 7y agoYes. From the ssh-keygen man page: > 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.
- m463 7y agohey you're right! I have removed '-b 521' from the ssh-keygen command.
- snowwrestler 7y agoI use a config file for all my regular SSH connections as well. But I stopped using more than one key when I could not think of a threat model that it addressed. 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.
- Piskvorrr 7y agoIt leaks information: "we have seen this one pubkey on multiple servers, therefore it's likely to be a key for everything plus the kitchen sink"
- mfontani 7y agoIf a bad guy gets root on one server you're currently connected via ssh with, and forwarding said key via, they can also access (unless otherwise firewalled) all systems that ssh key grants them access to. See also: https://github.com/FiloSottile/whoami.filippo.io 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 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.
- riedel 7y agoBut if you use agent forwarding with other keys loaded into the agent, how does hat help?
- mrweasel 7y agoI love the multiplexing feature. We have a client who require password, ssh key and MFA. All services are behind a bastion host, which only accepts trafic from select IPs. SSH multiplexing and proxy configuration allows me to enter the password and TOTP just once instead of every time I need to access a service behind the bastion host.
- zengargoyle 7y agoOf course if the multiplex stalls or goes down so do all of the connections you have running through it. It's like screwing up Gnome Terminal or similar that uses a main server and multiple clients. Screw one pooch and you're whole session of things is similarly screwed.
- MawKKe 7y agoAnother annoying "feature" is that opening a new shell with ssh -X will not enable the forwarding if the original master connection was not enabled with it.
- mrweasel 7y agoTrue, but I never see SSH go down, unless there's a network issue, in which case I lose all my connections anyway.
- beagle3 7y agoIndeed; however, if you have a lingering control file (because an old ssh process was killed, or there was a power failure and it was somehow not removed), it will either refuse to use it, or (occasionally, and I haven't been able to pinpoint when), would just wait there forever. edit: a typo
- dkdk8283 7y agoSounds more like a bug than a disadvantage
- 7y ago
- GrinningFool 7y agossh-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.
- vagab0nd 7y agoThat multiplex feature is really cool. Is there a way to make it work for pem files? It'll be super useful to specify "-i pem" once and use that for all subsequent ssh/scp. Same goes for the username.