The age is an open-source and cross-platform tool that allows to encrypt and decrypt files. This tool is written in Go programming language.
This tutorial demonstrates how to install and use age command on Ubuntu 20.04.
Install age
Get the latest version tag of age release from GitHub. Assign version tag to variable.
AGE_VERSION=$(curl -s "https://api.github.com/repos/FiloSottile/age/releases/latest" | grep -Po '"tag_name": "v\K[0-9.]+')
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-amd64.tar.gz"
Run the following command to 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 are available for all users as a system-wide commands.
We can check age version:
age -version
Remove tar.gz file and temporary directory:
rm -rf age.tar.gz
rm -rf age
Testing age
Create text file for testing:
echo 'Testing' > data.txt
The age-keygen allows to generate private and public key pair. Public key is used to encrypt data and private key to decrypt data.
age-keygen -o key.txt
Command creates a key.txt file which contains public key and private key.
cat key.txt
Example:
# created: 2021-09-25T10:51:25Z
# public key: age1k0kkexy3ahaqh0mhkh898wm28c0gwpntuh350fsqhaq9e3a7hapst2nthh
AGE-SECRET-KEY-1HSCCDGLWG3QU37F2GGLAFQQS5RJHM4UP7RTLS0NVRPJNRTJ820FQGS2VKS
Run age command to encrypt a file with public key:
age -r age1k0kkexy3ahaqh0mhkh898wm28c0gwpntuh350fsqhaq9e3a7hapst2nthh data.txt > data.txt.age
Now you can decrypt encrypted file with private key which stored in key.txt file:
age -d -i key.txt data.txt.age > data_decrypted.txt
Uninstall age
If you decided 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