DEV Community

Tony Metzidis
Tony Metzidis

Posted on

Passwordless SSH One-Liner

When you need to get your key onto another machine, and you don't want the silly login-logout-copy-paste nonsense. Do this:

$ cat ~/.ssh/id_rsa.pub | ssh pi@pihole3bplus.local bash -c "mkdir -p .ssh && cat >> .ssh/authorized_keys"

Don't have a key? Here's how to make one

ssh-keygen
# smash the enter button
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/tonymet/tmp/kaka.
Your public key has been saved in /Users/tonymet/tmp/kaka.pub.
The key fingerprint is:
SHA256:WXXXXX
The key's randomart image is:
+---[RSA 3072]----+
|o.+++=+*Bo=.     |
| . xxxxxxxxx . . |
|   xxxxxxxxx+ + .|
|  xxxxxxxxxx = . |
|     = .S . =    |
|      B    o .   |
|     + .         |
|      .          |
|                 |
+----[SHA256]-----+

Discussion (1)

Collapse
egelados profile image
Kostas Psarras

Maybe just:
ssh-copy-id -i ~/.ssh/mykey user@host
:)