How can I have passphrases for ssh-keys automatically saved and reused when entered for…
- User
How can I have passphrases for ssh-keys automatically saved and reused when entered for the first time in an XFCE session on a Debian system?
Assistant
To have SSH passphrases automatically saved and reused when entered for the first time in an XFCE session on a Debian system, you can use GNOME Keyring or KDE Wallet, but since XFCE is lightweight, the most compatible and widely used solution is to use
ssh-agentwithgnome-keyring.Here’s how to set it up so that your SSH key passphrase is remembered after the first login during an XFCE session:
✅ Step-by-Step Guide
1. Install Required Packages
Make sure
gnome-keyringand related packages are installed:sudo apt update sudo apt install gnome-keyring libpam-gnome-keyring seahorseseahorseis the GUI frontend (Passwords and Keys app) for managing stored credentials.
2. Configure PAM to Use GNOME Keyring
Ensure GNOME Keyring is started at login by configuring PAM (Pluggable Authentication Modules):
Edit the PAM configuration file:
sudo nano /etc/pam.d/common-sessionAdd this line at the end of the file:
session optional pam_gnome_keyring.so auto_startSave and exit.
3. Set Up Your Desktop Environment to Use GNOME Keyring
You need to make sure XFCE starts the GNOME Keyring properly.
Edit (or create) the autostart file for GNOME Keyring:
nano ~/.config/autostart/gnome-keyring-ssh.desktopAdd the following content:
[Desktop Entry] Name=SSH Key Agent (Gnome Keyring) Comment=GNOME Keyring SSH Agent Type=Application Exec=gnome-keyring-daemon --start --components=ssh OnlyShowIn=XFCE;GNOME; X-GNOME-Autostart-enabled=trueThis ensures the GNOME Keyring daemon starts with the SSH component enabled.
4. Optional: Configure
.bash_profileor Shell ProfileIf the environment variables aren’t being set correctly, you can ensure they are sourced by adding the following to your shell profile (
~/.bash_profile, or~/.profileif using another shell):if [ -n "$DESKTOP_SESSION" ]; then eval $(gnome-keyring-daemon --start --components=ssh) export SSH_AUTH_SOCK fiThis step may not be necessary if GNOME Keyring is integrated correctly via PAM/session startup.
5. Add Your SSH Key to the Keyring
After rebooting or logging out/in, open a terminal and add your SSH key:
ssh-add ~/.ssh/id_rsaYou will be prompted for your passphrase once. From now on, it should be remembered for the session.
🧪 Test It
Try connecting to a remote server:
ssh user@hostnameYou should not be prompted again for your passphrase.
🔁 Optional: Auto Add Keys at Startup
If you want specific keys added automatically when you log in:
- Run
ssh-add ~/.ssh/id_rsamanually once. - Then run:
to confirm it's added.ssh-add -l
The key will be remembered until you log out or restart.
If you want to automate this every session:
Create a script in
~/.config/autostart-scripts/or add it to XFCE's Session and Startup > Application Autostart.Example command:
ssh-add ~/.ssh/id_rsaYou can also use tools like
keychainas an alternative to manage persistent agents across sessions.
✅ Summary
Step Description Install gnome-keyring,libpam-gnome-keyring,seahorseConfigure PAM Add pam_gnome_keyring.so auto_startAutostart Create gnome-keyring-ssh.desktopShell setup (Optional) Ensure SSH_AUTH_SOCKis exportedAdd key Run ssh-addonce per key
Let me know if you're using a different display manager (like LightDM, GDM, or SDDM), or a non-default shell — these might require small adjustments!
- Run