Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/delphinus/gosshauth
A tiny hook tool for bash/zsh to re-authenticate with ssh-agent.
https://github.com/delphinus/gosshauth
bash ssh ssh-agent zsh
Last synced: 7 days ago
JSON representation
A tiny hook tool for bash/zsh to re-authenticate with ssh-agent.
- Host: GitHub
- URL: https://github.com/delphinus/gosshauth
- Owner: delphinus
- License: mit
- Created: 2018-07-18T05:59:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-12-17T05:27:23.000Z (almost 5 years ago)
- Last Synced: 2024-06-20T09:18:43.886Z (5 months ago)
- Topics: bash, ssh, ssh-agent, zsh
- Language: Go
- Homepage:
- Size: 41 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# `gosshauth`
A tiny hook tool for bash/zsh to re-authenticate with ssh-agent.
## What's this?
This small command manages sockets for SSH authentication created by
`ssh-agent`. It automatically detects the valid socket and rewrite the symlink
to avoid disconnecting.## When do I need this?
`ssh-agent` stores the path for sockets into `$SSH_AUTH_SOCK`. It is a path
below, for instance.```sh
# example in macOS
$ echo $SSH_AUTH_SOCK
/private/tmp/com.apple.launchd.sa197Z7kVN/Listeners
```This changes every time you login and `ssh-agent` detects the changes and makes
`$SSH_AUTH_SOCK` indicate validly. Usually that's enough.But when you use terminal multiplexers -- `tmux`, `screen`, or so --, it breaks
this.## Reproducible way
1. Login your Mac.
- `$SSH_AUTH_SOCK` is `/some/path/to/Listeners`.
2. SSH into a Linux box.
- `$SSH_AUTH_SOCK` will be changed into `/tmp/path/to/agent.foo`.
3. Launch `tmux` in the box. Also you can use SSH authentication in `tmux` by
`ssh-agent`.
4. Detach `tmux` and logout the box.
5. SSH into the box again.
- `$SSH_AUTH_SOCK` will be changed into `/tmp/path/to/agent.bar`.
6. Attach the existent `tmux` session.
7. `$SSH_AUTH_SOCK` will be `/tmp/path/to/ssh-agent.foo`, not `...bar`.
You can NOT use SSH authentcation in it.## Solution
Here is `gosshauth`. You can install this from [release page][] or a command
below.[release page]: https://github.com/delphinus/gosshauth/releases
```sh
go get github.com/delphinus/gosshauth
```And you should set the hook for zsh/bash.
```bash
# for bash
if which gosshauth > /dev/null 2>&1; then
eval "$(gosshauth hook bash)"
fi
``````zsh
# for zsh
if (( $+commands[gosshauth] )); then
eval "$(gosshauth hook zsh)"
fi
``````fish
# for fish
if type -q gosshauth
gosshauth hook fish | source
end
```Now you can use SSH authentication even if in the way above.
## How do `gosshauth` work for this?
1. Check `$SSH_AUTH_SOCK`.
2. `gosshauth` checks the existence.
- If exists, that's all, done.
3. `gosshauth` globs all socket-like files for `/tmp/**/Listeners` and
`/tmp/ssh*/agent.*`.
4. The candidate that has the latest timestamp is the goal, maybe. `gosshauth`
rewrite the `~/.ssh/auth_sock` symlink to target the goal, and set
`$SSH_AUTH_SOCK` to use it.## Author
JINNOUCHI Yasushi <[email protected]>
## License
The MIT License