Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ It is assumed that your login password is identical to the password of the keys.

For Arch Linux users is already a [pam_exec-ssh-git](https://aur.archlinux.org/packages/pam_exec-ssh-git/) package in the AUR.

Otherwise just copy the script, set the permissions and install the dependencies `pam` and `expect`.
Otherwise just copy the script, set the permissions and install the dependencies `pam` and `expect` and optionally `keychain`.

```sh
cp pam_exec-ssh /usr/bin/pam_exec-ssh
Expand All @@ -26,7 +26,14 @@ chmod 755 /usr/bin/pam_exec-ssh
## Configuration

You need a running `ssh-agent` that have to be started before you login.
You can start your agent [manually](https://wiki.archlinux.org/index.php/SSH_keys#ssh-agent) or as a [systemd user service](https://wiki.archlinux.org/index.php/SSH_keys#Start_ssh-agent_with_systemd_user).
If you have `keychain` installed, the script will run it and start the `ssh-agent` automatically.
Be sure to also start it in your `~/.bashrc` to get the environment variables set correctly, for example:

```
eval $(keychain --eval --quiet)
```

Of course you can also start your agent [manually](https://wiki.archlinux.org/index.php/SSH_keys#ssh-agent) or as a [systemd user service](https://wiki.archlinux.org/index.php/SSH_keys#Start_ssh-agent_with_systemd_user).

Make sure that the socket path is correct.
`pam_exec-ssh` use `/run/user/YOUR-USER-ID/ssh-agent.socket` for it.
Expand Down
8 changes: 6 additions & 2 deletions pam_exec-ssh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ else
read -r PAM_PASS
PAM_PASS=$(echo "$PAM_PASS" | sed 's/\$/\\\$/')

SSH_AUTH_SOCK=/run/user/$(id -u "$PAM_USER")/ssh-agent.socket
export SSH_AUTH_SOCK
if hash keychain 2>/dev/null; then
eval "$(keychain --eval --quiet)"
else
SSH_AUTH_SOCK=/run/user/$(id -u "$PAM_USER")/ssh-agent.socket
export SSH_AUTH_SOCK
fi

find "$unlockdir" -maxdepth 1 ! -wholename "$unlockdir" | while read -r key; do
printf 'log_user 1\n\nspawn ssh-add "%s"\n\nexpect "Enter passphrase for %s" {\nsend "%s\r"\n}\n\nexpect eof' "$key" "$key" "$PAM_PASS" | expect
Expand Down