The age is an open-source and cross-platform tool for encrypting and decrypting files via command line. This tool is written in Go programming language.
This tutorial explains how to install and use age command on Raspberry Pi.
Install age
Connect to Raspberry Pi via SSH and retrieve the latest version tag of age
release from GitHub:
AGE_VERSION=$(curl -s "https://api.github.com/repos/FiloSottile/age/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')
Run the following command to download tar.gz
file from releases page of the age
repository:
curl -Lo age.tar.gz "https://github.com/FiloSottile/age/releases/latest/download/age-v${AGE_VERSION}-linux-arm.tar.gz"
Next, extract a tar.gz
file:
tar xf age.tar.gz
Move age
and age-keygen
commands to /usr/local/bin
directory.
sudo mv age/age /usr/local/bin
sudo mv age/age-keygen /usr/local/bin
Now both commands will be available for all users.
We can check age
version as follows:
age -version
Remove tar.gz
file and temporary directory:
rm -rf age.tar.gz
rm -rf age
Testing age
For testing purpose create text file:
echo 'Testing' > data.txt
The age-keygen
command can be used for generating private and public key pair. Data is encrypted with public key and decrypted with private key.
age-keygen -o key.txt
A key.txt
file was created which holds public key and private key.
cat key.txt
Example:
# created: 2021-12-12T03:43:59Z
# public key: age1s3t8uu7rpsljufpfp06m9pd352dn3nd0hgs68y4w4l75hrsflytsrekd90
AGE-SECRET-KEY-12PPH7GHP6DJ2JUWJ05XAJFNYQGF79A8F65G9EMNGWHMX2ASW6PPSR33UGK
Run age
command to encrypt a file with public key:
age -r age1s3t8uu7rpsljufpfp06m9pd352dn3nd0hgs68y4w4l75hrsflytsrekd90 data.txt > data.txt.age
Now encrypted file can be decrypted with private key which stored in key.txt
file:
age -d -i key.txt data.txt.age > data_decrypted.txt
Uninstall age
If you want to completely remove age, delete the following files:
sudo rm -rf /usr/local/bin/age
sudo rm -rf /usr/local/bin/age-keygen
Leave a Comment
Cancel reply