Skip to content
TheChatArchiveThe Chat Archive
Qwenqwen3-235b-a22b-no-thinking· Alibaba (Qwen)Hugging Face LMArena Human Preference 140K

How can I have passphrases for ssh-keys automatically saved and reused when entered for…

  1. 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?

  2. Qwen 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-agent with gnome-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-keyring and related packages are installed:

    sudo apt update
    sudo apt install gnome-keyring libpam-gnome-keyring seahorse
    

    seahorse is 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-session
    

    Add this line at the end of the file:

    session optional pam_gnome_keyring.so auto_start
    

    Save 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.desktop
    

    Add 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=true
    

    This ensures the GNOME Keyring daemon starts with the SSH component enabled.


    4. Optional: Configure .bash_profile or Shell Profile

    If 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 ~/.profile if using another shell):

    if [ -n "$DESKTOP_SESSION" ]; then
      eval $(gnome-keyring-daemon --start --components=ssh)
      export SSH_AUTH_SOCK
    fi
    

    This 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_rsa
    

    You 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@hostname
    

    You 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:

    1. Run ssh-add ~/.ssh/id_rsa manually once.
    2. Then run:
      ssh-add -l
      
      to confirm it's added.

    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_rsa
    

    You can also use tools like keychain as an alternative to manage persistent agents across sessions.


    ✅ Summary

    StepDescription
    Installgnome-keyring, libpam-gnome-keyring, seahorse
    Configure PAMAdd pam_gnome_keyring.so auto_start
    AutostartCreate gnome-keyring-ssh.desktop
    Shell setup(Optional) Ensure SSH_AUTH_SOCK is exported
    Add keyRun ssh-add once 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!