Table of Contents
Use environment variables to store sensitive information
Use secret-tool to store and obtain passwords
Centralized key management with Vault
Pay attention to permissions and encrypted transmissions

How to manage secrets on Linux

Aug 24, 2025 am 12:52 AM

Managing keys and sensitive information on Linux systems requires the following principles of secure storage and access control. 1. Use environment variables to pass sensitive data, avoid hard coding, and reasonably set persistent file permissions; 2. Use secret-tool tool to encrypt storage passwords, suitable for desktop applications; 3. Use Vault to implement centralized key management, suitable for team and production environments; 4. Strictly limit sensitive file permissions, avoid plaintext output, and use HTTPS transmission to prevent key leakage.

How to manage secrets on Linux

Managing keys and sensitive information on Linux systems (such as passwords, API keys, etc.) is an important part of system security. Many people simply write their passwords in configuration files, which is actually very dangerous. Here are some practical ways to help you manage secret information more securely on Linux.


Use environment variables to store sensitive information

Environment variables are a common but effective way to pass sensitive data, especially when running scripts or services.

  • Avoid hard-code : Do not write passwords or keys directly into code or configuration files.
  • Temporary settings : You can temporarily set environment variables on the command line, for example:
     export API_KEY="your-secret-key"
  • Pay attention to security when persisting : If you need to save it persistently, you can place it in the user's ~/.bashrc or ~/.zshrc , but it is recommended to use it only when necessary and ensure that the permissions of these files are set correctly (for example, using chmod 600 ~/.bashrc ).

Use secret-tool to store and obtain passwords

Linux provides a GNOME Keyring-based tool secret-tool that can be used to securely store and retrieve passwords.

  • Installation method (Debian/Ubuntu):
     sudo apt install libsecret-1-dev
  • Store password:
     secret-tool store --label="MyApp Password" service "myapp" username "user"
  • Get the password:
     secret-tool lookup service "myapp" username "user"

The advantage of this method is that the password is encrypted and stored and is bound to the user session, which is suitable for desktop applications or scenarios with graphical interfaces.


Centralized key management with Vault

If you are operating in a team or production environment, it is recommended to use HashiCorp Vault to manage keys uniformly.

  • Advantages : Supports dynamic key generation, access control, audit log and other functions.
  • Basic process :
    • Install and start Vault
    • Setting up policies and access tokens
    • Store the key:
       vault kv put secret/myapp password="super-secret"
    • Get the key:
       vault kv get secret/myapp

Vault is powerful, but has a slightly high deployment and maintenance cost, making it suitable for scenarios with high security requirements.


Pay attention to permissions and encrypted transmissions

No matter which method you use, don't forget the most basic points:

  • All files containing sensitive information should be restricted, such as:
     chmod 600 /path/to/secret/file
  • When using sensitive information in scripts, try to avoid plaintext output, such as when debugging shell scripts with the -x parameter, the command content will be exposed.
  • If you are calling the API remotely, remember to use HTTPS and verify the certificate to prevent the middleman from stealing the key.

Basically that's it. Although each method applies to different scenarios, the core principle is: don’t let sensitive information run naked.

The above is the detailed content of How to manage secrets on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1596
276
How to trace network path using traceroute How to trace network path using traceroute Aug 02, 2025 am 12:23 AM

When you encounter a problem with slow network connection, traceroute can help you locate the bottleneck. It is a command line tool that displays the path through which the data packets pass from your computer to the target server by sending probe packets and recording the response time of each step. How to use it is tracertexample.com under Windows and tracerouteexample.com under macOS/Linux/Unix. In the output result, each line represents an intermediate node, including the number of hops, three round trip times and the corresponding IP or host name; if all hops are *, it may be firewall blocking or network failure. Check the jump with delay burst to determine the location of the problem; combined with multiple domain name tests, you can distinguish between general

How to manage packages on CentOS RHEL yum dnf How to manage packages on CentOS RHEL yum dnf Aug 01, 2025 am 12:22 AM

CentOS or RHEL systems recommend using yum and dnf management software packages. 1. It is recommended to update the cache first during installation, the commands are sudoyumininstall and sudodnfinstall respectively; 2. You can update yumupdate or dnfupgrade, and you can view the list to be updated; 3. Use yumremove or dnfremove to delete, and dnf can automatically clean up useless dependencies; 4. Query to view the installation status through rpm-qa and rpm-q, and yuminfo/dnfinfo get detailed information. Mastering these operations can help to efficiently maintain the system.

How to troubleshoot Kubernetes nodes How to troubleshoot Kubernetes nodes Aug 02, 2025 am 02:44 AM

To troubleshoot Kubernetes node problems, follow the steps: 1. Use kubectlgetnodes and describenode to view the node status and detailed information, and pay attention to the exceptions in Conditions; 2. Log in to the node to check whether the kubelet status, logs and container runtime are normal; 3. Check the network connection and firewall settings to ensure that the port communication with APIServer is normal; 4. Check the CNI plug-in status and related logs. Through the above methods, the cause of the problem can be basically located, and the problem can be effectively solved by checking it in order.

How to decrypt files on Linux How to decrypt files on Linux Aug 02, 2025 am 02:57 AM

When encountering an encrypted file, you must first identify the encryption type and then use the corresponding tool to decrypt it. 1. Confirm the encryption method, such as GPG or OpenSSL encryption, through file extension or file command; 2. To decrypt GPG files with gpg command, you need to enter a password or private key such as gpg-ooutput_file-dencrypted_file.gpg; 3. OpenSSL decryption requires specifying algorithm mode such as opensslaes-256-cbc-d-inencrypted_file.enc-outdecrypted_file; 4. File system encryption, such as eCryptfs, automatically decrypts the compressed package after logging in, you can enter the password to decompress.

How to compile a kernel module How to compile a kernel module Aug 01, 2025 am 12:05 AM

Tocompileakernelmodule,firstinstallbuildtoolsandheadersspecifictoyourdistribution.OnDebian-basedsystems,runsudoaptupdateandsudoaptinstallbuild-essentiallinux-headers-$(uname-r);onRedHat-basedsystems,usesudodnfgroupinstall"DevelopmentTools"a

How to list firewall rules How to list firewall rules Jul 29, 2025 am 12:02 AM

To view firewall rules, you need to select the corresponding method based on the operating system and platform. 1. When using iptables in Linux system, execute sudoiptables-L-n-v or add-x to view detailed rules; if using nftables, use nftlistruleset. 2. Ubuntu's UFW firewall uses sudoufwstatusverbose to view status and rules, or read /etc/ufw/user.rules file. 3. Windows uses the PowerShell command Get-NetFirewallRule to view inbound rules, or browse through the graphical interface management console. 4. Cloud platforms such as AWS in EC

How to roll back system updates How to roll back system updates Aug 01, 2025 am 01:08 AM

The method of rolling back the system update varies from operating system to different operating system, so you need to operate with caution and backup in advance. For Windows, it can be achieved by "Settings → Update and Security → Windows Update → View Update History → Uninstall Update", but some cumulative updates cannot be uninstalled directly; macOS needs to rely on TimeMachine backup and restore or reinstall old versions, and it is difficult to downgrade; iOS can only be downgraded within a specific signature period, while Android depends on the brand and Bootloader unlock status, and data must be backed up before flashing; Linux users can use snapshots or log rollbacks, but they need to master command line operations. Overall, you should understand the system mechanism in detail and do a good job of data protection before rolling back.

How to update packages using apt How to update packages using apt Aug 11, 2025 pm 01:07 PM

To update Linux system packages, you must first run sudoaptupdate to refresh the source list, otherwise it may cause the installation to fail or the version is too old. 1. Update the software source: execute sudoaptupdate; 2. Upgrade the software package: It is recommended to use sudoaptfull-upgrade to completely upgrade and install new dependencies, but be careful to uninstall conflict packages; 3. Clean useless packages: Use sudoaptautoremove and sudoaptclean to release disk space; in addition, when encountering GPG errors, you should check the key. If you connect to a connection problem, you can try to replace the domestic mirror source. Usually, you can use aptlist-upgradable to view the upgradeable package, or complete it at one time with the command chain.

See all articles