CyberLibrary
Cover Image

SSH-foo

Posted on 1 min

Ubuntu Linux Ssh

A small compilation of useful commands in Linux for handling SSH keys.

Generate new SSH key

You will be asked for a passphrase for the private key.

ssh-keygen -t ed25519 -o -a 321 -f ~/.ssh/ssh_key -C "${USER}@${HOST}4<PURPOSE>"

Not recommended: Creates a new ssh key without asking for a passphrase. Results in an unprotected private key!

ssh-keygen -t ed25519 -o -a 321 -f ~/.ssh/weak_ssh_key -C "${USER}@${HOST}4<PURPOSE>" -N ""

Copy public key into clipboard

  1. Command: If missing, install clipboard.
  2. Command: Put public key into clipboard without trailing newline (-n).
  3. Ready to go. Use Ctrl+v now wherever you need to paste.
sudo apt update -y && sudo apt install xclip -y
echo -n `cat ~/.ssh/ssh_key.pub` | xclip -selection clipboard

To store the public key on a server, use the following command instead.

ssh-copy-id user@hostname.domain.tld

Multiple SSH keys? Be more specific. The option -i works as well for the command ssh.

ssh-copy-id -i ~/.ssh/ssh_key.pub user@hostname.domain.tld