This activity is intended to introduce asymmetric encryption tools.
ssh-keygen
ssh-copy-id student@ipaddress
ssh student@ipaddress
ssh-agent is a daemon you can run to supply your ssh keys when needed. If you add your keys to the daemon, it will ask for each key file decryption passphrase when it adds those keys, and then you will no longer need to give the passphrase to use those keys until the daemon ends. The daemon is run per user so that no user has access to any other user’s ssh-agent daemon. To try it, you can use the following commands to start the daemon if you do not already have it running, add your keys if they aren’t already there, and give you a status report on the daemon. You can add these lines to the end of your ~/.bashrc file if you want to always have your ssh keys available through the daemon whenever you log into the system.
pgrep -u $USER ssh-agent 2>&1 >/dev/null || ssh-agent -s >~/.ssh/agent-vars.sh
[ -f ~/.ssh/agent-var.sh ] && source ~/.ssh/agent-vars.sh
pgrep -u $USER ssh-agent 2>&1 >/dev/null && ssh-add -l || ssh-add
When keys are generated, an algorithm is chosen based on the purpose of the key. When the key is used for encryption and decryption, we call the output a private key. When the key is intended for use in signing or key exchange, we call that the output a set of parameters. For encryption, we typically use RSA, but may use EC with one of several specified curves. For key exchange, we use DH or ECDH. For signing, we use DSA, ECDSA, Ed25519, or Ed448.
# 2K bit RSA key generation
openssl genpkey -algorithm rsa -pkeyopt rsa_keygen_bits:2048 -out my-rsa-private-key.pem
# 2K bit DH parameters and key exchange parameters generation
openssl dhparam 2048 >dhparamsfile.pem
openssl genpkey -paramfile dhparamsfile.pem -out my-dh-private-key.pem
rm dhparamsfile.pem
# 2K bit DSA signing key generation
openssl dsaparam 2048 >dsaparamsfile.pem
openssl genpkey -out my-dsa-private-key.pem -paramfile dsaparamsfile.pem
rm dsaparamsfile.pem
# 256 bit ECDSA signing key generation
openssl genpkey -algorithm ec -pkeyopt ec_paramgen_curve:secp384r1 -out my-ecdsa-private-key.pem
# Ed25519 signing key generation
openssl genpkey -algorithm ed25519 -out my-ed25519-private-key.pem
# Ed448 signing key generation
openssl genpkey -algorithm ed448 -out my-ed448-private-key.pem
openssl pkey -in my-rsa-private-key.pem -text -noout
openssl pkey -in my-dh-private-key.pem -text -noout
openssl pkey -in my-dsa-private-key.pem -text -noout
openssl pkey -in my-ecdsa-private-key.pem -text -noout
openssl pkey -in my-ed25519-private-key.pem -text -noout
openssl pkey -in my-ed448-private-key.pem -text -noout
echo standard-resolver > ~/.gnupg/dirmngr.conf
pkill -u `id -un` dirmngr
gpg --gen-key
gpg --armor --export keyname
gpg --keyserver keyserver.ubuntu.com --send-keys keyfingerprintstring
gpg --keyserver keyserver.ubuntu.com --search-keys "name for key"
somethingtocreateamessage | gpg --encrypt --sign --armor --recipient recipientid >gpg-encrypted-message-for-recipientid
cat encryptedmessagefile|gpg --decrypt