Lauri's notes

Generating keys

Setup SSH

# Prepare .ssh folder and files
mkdir ~/.ssh
chmod 700 ~/.ssh
touch ~/.ssh/authorized_keys ~/.ssh/config ~/.ssh/known_hosts
chmod 600 ~/.ssh/authorized_keys ~/.ssh/config ~/.ssh/known_hosts

# Generating SSH keys
ssh-keygen -t rsa -b 2048 -C "me@email.adr"

# Pull from remote
ssh host "cat ~/.ssh/" >> ~/.ssh/authorized_keys

# Push to remote
ssh host "cat - >> ~/.ssh/authorized_keys" < ~/.ssh/

Convert SSH keys for GnuPG

# create a certificate for ssh key:
$ openssl req -new -x509 -key ~/.ssh/id_rsa -out ~/.ssh/id_rsa.pem
# import it in GnuPG
$ openssl pkcs12 -export -in ~/.ssh/id_rsa.pem -inkey ~/.ssh/id_rsa -out ~/.ssh/id_rsa.p12
$ gpg --import ~/.ssh/id_rsa.p12


# keep master connection open to speed up usage
ssh -N

chmod 700 ~/.gnupg

chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/

# Create a public SSH key from the private key
ssh-keygen -f ~/.ssh/id_rsa -y > ~/.ssh/

# Compare a remote file with a local file
ssh user@host cat /path/remotefile | diff /path/localfile -

# SSH network throughput test
yes | pv | ssh user@host "cat > /dev/null"

Tags: ssh, gnupg

Have an update or suggestion for this note? You can edit it and send me a pull request.

Since 2009 to 2024