Skip to content

add ssh-agent support to store SSH key passphrases - #1661

Closed
sgruendel wants to merge 30 commits into
omacom:devfrom
sgruendel:ssh_agent
Closed

sgruendel wants to merge 30 commits into
omacom:devfrom
sgruendel:ssh_agent

Conversation

@sgruendel

Copy link
Copy Markdown
Contributor

@dhh

dhh commented Sep 14, 2025

Copy link
Copy Markdown
Contributor

I use 1password as my ssh agent, so this wouldn't be a good fit for a default setup, but I'm open to the idea that we could have a way to add this on as an optional service installation.

@sgruendel

Copy link
Copy Markdown
Contributor Author

I use 1password as my ssh agent, so this wouldn't be a good fit for a default setup, but I'm open to the idea that we could have a way to add this on as an optional service installation.

Where would you see it then? "Install > Service", like Bitwarden?

@dhh

dhh commented Sep 14, 2025

Copy link
Copy Markdown
Contributor

That's what I'm thinking for now?

Comment thread bin/omarchy-install-ssh-agent Outdated
# Start ssh-agent automatically for user
systemctl enable --user ssh-agent.service

echo 'SSH Agent has been installed and enabled. Please reboot to apply changes.' No newline at end of file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe create $HOME/.local/state/omarchy/reboot-required and call omarchy-update-restart @dhh ?

Comment thread bin/omarchy-install-ssh-agent Resolved
@sgruendel
sgruendel marked this pull request as draft September 16, 2025 04:29
@Traap

Traap commented Sep 16, 2025

Copy link
Copy Markdown
Contributor

I cannot use 1password for various reasons on all my machine, so I hook a bash script into my .bashrc with the following.
sshkeys script.

#!/bin/bash

sshkeys() {
  local agentName agentCheck=1 cmpTo
  local AGENT_ENV_FILE="${HOME}/.ssh/agent_env"

  case "$OSTYPE" in
    msys*)   agentName="/usr/bin/ssh-agent"; cmpTo=0 ;;
    linux*)  agentName="ssh-agent";          cmpTo=1 ;;
    *)       echo "Unsupported OS: $OSTYPE"; return 1 ;;
  esac

  # Load existing agent vars if the file exists
  if [[ -f "$AGENT_ENV_FILE" ]]; then
    source "$AGENT_ENV_FILE" > /dev/null

    # Check if agent is alive and socket exists
    if ! kill -0 "$SSH_AGENT_PID" 2>/dev/null || [[ ! -S "$SSH_AUTH_SOCK" ]]; then
      rm -f "$AGENT_ENV_FILE"
      unset SSH_AGENT_PID SSH_AUTH_SOCK
    fi
  fi

  # Start a new agent if necessary
  if [[ -z "$SSH_AGENT_PID" || -z "$SSH_AUTH_SOCK" ]]; then
    eval "$(ssh-agent -s)" > /dev/null
    echo "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK" > "$AGENT_ENV_FILE"
    echo "export SSH_AGENT_PID=$SSH_AGENT_PID" >> "$AGENT_ENV_FILE"

    # Add keys only when a new agent is started
    if [[ -d $SSHHOME ]]; then
      for key in "$SSHHOME"/*.pub; do
        if [[ ! -f "$key" ]]; then
          echo "ERROR: $SSHHOME does not have any public keys."
          continue
        else
          echo "ssh-add: ${key%.*}"
          ssh-add "${key%.*}" 2>/dev/null
        fi
      done
    else
      echo "ERROR: SSHHOME is not defined or not a directory."
    fi
  fi
}

sshkeys "$@"

@sgruendel
sgruendel marked this pull request as ready for review September 20, 2025 12:38
Comment thread bin/omarchy-menu Resolved
woopstar added a commit to woopstar/omarchy that referenced this pull request Sep 22, 2025
woopstar added a commit to woopstar/omarchy that referenced this pull request Sep 22, 2025
@woopstar

Copy link
Copy Markdown
Contributor

Does this also fix #730 ?

Comment thread bin/omarchy-install-ssh-agent Outdated
@@ -0,0 +1,15 @@
#!/bin/bash

# add ssh keys to ssh-agent

@sudomateo sudomateo Sep 24, 2025 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't actually add SSH keys to the agent. It just creates the client configuration for it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clarified the comment, thanks for pointing this out

@gregid

gregid commented Oct 20, 2025

Copy link
Copy Markdown

That would be a nice addition as a service to install - are there blockers for the change? If not just bumping it.

@sgruendel

Copy link
Copy Markdown
Contributor Author

Once that's added, I believe this is a very relevant addition. Not everyone uses 1Password, and ssh-gent is a much more standard approach. Moving forward, we could even add options for other agents like Bitwarden to the install menu.

Yeah I've switched to Bitwarden as SSH agent some weeks ago, just created #5024 to make this available.

Copilot AI review requested due to automatic review settings March 27, 2026 19:11

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread bin/omarchy-install-ssh-agent Outdated
echo 'AddKeysToAgent yes' | tee -a ~/.ssh/config >/dev/null

# Ensure Hyprland picks up the SSH_AUTH_SOCK variable
echo 'env = SSH_AUTH_SOCK,$XDG_RUNTIME_DIR/ssh-agent.socket' | tee -a ~/.config/uwsm/env >/dev/null

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the correct syntax for uwsm/env, needs to be normal export.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Copilot AI review requested due to automatic review settings May 3, 2026 13:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings May 6, 2026 19:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

Copilot AI review requested due to automatic review settings May 9, 2026 19:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

Copilot AI review requested due to automatic review settings May 20, 2026 19:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

@csfh

csfh commented Sep 13, 2026

Copy link
Copy Markdown
Member

Hi!

Please update the PR description and double check the source branch which will allow us to review it.

@omarchybot

omarchybot commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

Thank you for this, @sgruendel. Caching SSH key passphrases is a real need, and this PR is where the idea of offering an agent as an optional service started. It is being closed in favour of #9399, which does the same job on quattro with gcr-ssh-agent (already on every install through gnome-keyring): it prompts graphically, so editors and other tools work without a terminal, it leaves ~/.ssh/config alone, and it ships a Remove entry. Omarchy would rather carry one optional agent than two.

This branch targets dev, and on quattro the menu it edits is now omarchy-menu.jsonc and ~/.config/uwsm/env is retired, so it would need rewriting rather than retargeting. Two things worth knowing for any future version: appending AddKeysToAgent yes to the end of ~/.ssh/config puts it inside the last Host or Match block, where it only applies to that host, and a second run appends it again.

Read by Claude Opus 5.5 and by Codex Medium, which was asked separately and agreed, though its independence is not guaranteed; nothing was run. Closed at the maintainer's request. If #9399 doesn't cover your case, say so there or reopen this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.