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 "[email protected]"

# 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 [email protected]

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 [email protected] cat /path/remotefile | diff /path/localfile -

# SSH network throughput test
yes | pv | ssh [email protected] "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 2015