Skip to main content
  1. Posts/

Making Use of GitHub Public Keys

·2 mins

If you haven’t already know by now, Github exposes user public keys at .keys repo. This is a great way to share your public keys with others. Here are two ways you can make use of this feature:

How to grant SSH access to GitHub user? #

Command #

curl https://github.com/<username>.keys >> ~/.ssh/authorized_keys

Explanation #

curl is a command-line tool that is used to transfer data to or from a server. The above command fetches the public keys of the user and appends them to the authorized_keys file in the ~/.ssh directory. This allows the user to SSH into the machine using their private key.

How to encrypt a file using Github user? #

To encrypt a file using their public key, you can pipe the public keys to age. Age is a modern encryption tool that is easy to use and secure. It is a great alternative to GPG.

Command #

curl https://github.com/<username>.keys | age -R - image.jpg > image.jpg.age

Explanation #

curl is a command-line tool that is used to transfer data to or from a server. The above command fetches the public keys of the user and pipes them to the age command. The -R flag tells age to read the public keys from the standard input. The - flag tells age to read the file to be encrypted from the standard input. The encrypted file is then saved as image.jpg.age.

How to decrypt a file using your private key? #

Command #

age -d -i ~/.ssh/id_ed25519 image.jpg.age > image.jpg

Explanation #

The above command decrypts the file image.jpg.age using the private key found in ~/.ssh/id_ed25519 and saves the decrypted file as image.jpg.