Skip to main content

Managing Password in Unix Using Pass

If you are looking for simple password management in Unix, pass maybe the answer. It utilizes GPG to encrypt the stored passwords. It stores the encrypted passwords as text files in a tree of directories. Each directory can maintain a separate GPG key for encrypting the passwords stored inside it.

How easy is it? The following command shows how we can store a password and set AWS/access-key-id as the variable name to access it in the future.

pass insert AWS/access-key-id

The previous command will automatically create a directory named AWS inside the ~/.password-store directory which is the default location of pass storage. It also creates a file named access-key-id.gpg inside the ~/.password-store/AWS directory. To access the value we can call the following command.

pass AWS/access-key-id

There are some steps we need to run for utilizing the tool.

  1. Install pass using package manager
  2. Create a GPG key pair record
  3. Initialize the pass storage with the specified GPG key
  4. Store the passwords

Install pass
apt install pass

Create a GPG record

We can utilize the GPG tool available in Linux or we can install it from the package manager if it has not been installed yet. We can omit the requested passphrase for generating unprotected GPG key pair. Even though it is not recommended, it can be useful when we will use the password in an automation process.

gpg --generate-key

Then, we can list all the generated keys using the following command. The public ID part will be required when we want to initialize the  pass storage.

gpg --list-keys

Initialize the pass storage

We set the root directory of the pass storage to utilize our GPG key generated in the previous step. For example, the public ID is ABCXYZ.

pass init "ABCXYZ"

The previous command will create a .gpg-id file inside the ~/.password-store directory. The file contains GPG public ID that is being used in the directory.


Store the passwords

Now, we can store any passwords using the following format.

pass insert hello/world/my-secret

The previous command will create a my-secret.gpg file inside the ~/.password-store/hello/world directory.


Additional GPG keys

We can generate more GPG key pairs, some are protected with a passphrase, to store more data with different encryption keys. In this case, we have to differentiate the directories in the pass initialization step. For example, we want all passwords in the ~/.password-store/secured directory to use a passphrase-protected GPG key.

gpg --generate-key
gpg --list-keys
pass init -p secured "new_secured_GPG_public_id"

The previous command will generate another .gpg-id file inside the ~/.password-store/secured directory. Then, any records stored in the specified directory will use the GPG key which is different from the key available in the root directory of the storage (~/.password-store). For instance, we can store a new record using the following format.

pass insert secured/AWS/access-key-id

Any time we need to get the value of secured/AWS/access-key-id, we will be asked for a passphrase.


Example use case

We can access a secret value and pass it into the environment variable by running the following command.

export MY_VAR=$(pass hello/world/my-secret)

Comments

Popular posts from this blog

Increase of Malicious Activities and Implementation of reCaptcha

In recent time, I've seen the increase of malicious activities such as login attempts or phishing emails to some accounts I manage. Let me list some of them and the actions taken. SSH Access Attempts This happened on a server that host a Gitlab server. Because of this case, I started to limit the incoming traffic to the server using internal and cloud firewall provided by the cloud provider. I limit the exposed ports, connected network interfaces, and allowed protocols. Phishing Attempts This typically happened through email and messaging platform such as Whatsapp and Facebook Page messaging. The malicious actors tried to share a suspicious link lured as invoice, support ticket, or something else. Malicious links shared Spammy Bot The actors leverage one of public endpoint on my website to send emails. Actually, the emails won't be forwarded anywhere except to my own email so this just full my inbox. This bot is quite active, but I'm still not sure what...

Configuring Swap Memory on Ubuntu Using Ansible

If we maintain a Linux machine with a low memory capacity while we are required to run an application with high memory consumption, enabling swap memory is an option. Ansible can be utilized as a helper tool to automate the creation of swap memory. A swap file can be allocated in the available storage of the machine. The swap file then can be assigned as a swap memory. Firstly, we should prepare the inventory file. The following snippet is an example, you must provide your own configuration. [server] 192.168.1.2 [server:vars] ansible_user=root ansible_ssh_private_key_file=~/.ssh/id_rsa Secondly, we need to prepare the task file that contains not only the tasks but also some variables and connection information. For instance, we set /swapfile  as the name of our swap file. We also set the swap memory size to 2GB and the swappiness level to 60. - hosts: server become: true vars: swap_vars: size: 2G swappiness: 60 For simplicity, we only check the...

Deliver SaaS According Twelve-Factor App

If you haven't heard of  the twelve-factor app , it gives us a recommendation or a methodology for developing SaaS or web apps structured into twelve items. The recommendation has some connections with microservice architecture and cloud-native environments which become more popular today. We can learn the details on its website . In this post, we will do a quick review of the twelve points. One Codebase Multiple Deployment We should maintain only one codebase for our application even though the application may be deployed into multiple environments like development, staging, and production. Having multiple codebases will lead to any kinds of complicated issues. Explicitly State Dependencies All the dependencies for running our application should be stated in the project itself. Many programming languages have a kind of file that maintains a list of the dependencies like package.json in Node.js. We should also be aware of the dependencies related to the pla...

Kenshin VS The Assassin

It is an assassin versus assassin.

Free Cloud Services from UpCloud

Although I typically deploy my development environment or experimental services on UpCloud , I do not always stay updated on its announcements. Recently, I discovered that UpCloud has introduced a new plan called the Essentials plan, which enables certain cloud services to be deployed at no cost. The complimentary services are generally associated with network components or serve as the foundation for other cloud services. This feature is particularly useful when retaining foundational services, such as a load balancer, is necessary, while tearing down all services and reconfiguring the DNS and other application settings each time we temporarily clean up infrastructure to reduce costs is undesirable.  When reviewing the service specifications of the cloud services in the Essentials plan, they appear to be very similar to those in the Development plan. The difference in service levels is unclear, but it could be related to hardware or resource allocation. For instance, the loa...

Handling PDF Generation in Web Service

If we are building a website that requires a PDF generation feature, there are several options for implementing it based on the use cases or user requirements. First, we can generate the PDF on the client side using any available client library. It is suitable if the use case is to print out some data that is already available inside certain website components, and we want to maintain the styles of the components in the document. Second, we can do it fully in the back-end using any library available, such as PDF-lib, jsPDF, and so on. This approach is suitable if we want to keep the data processing or any related business functions in the back-end server. This second approach might have disadvantages, such as the difficulty of maintaining the design assets and styles which are already on our website. Third, it is using a hybrid approach, where certain processes are handled on the client side, and some are handled on the back-end. In this post, I want to discuss more about the...