feat: implement import/export functionality for SSH keys and configs
parent
f362ffa12b
commit
8c12edb583
2
Makefile
2
Makefile
|
|
@ -1,6 +1,6 @@
|
||||||
install:
|
install:
|
||||||
@echo "Installing pass-cli plugin (sshkeys.bash)..."
|
@echo "Installing pass-cli plugin (sshkeys.bash)..."
|
||||||
@mkdir -p ~/.password-store/.extensions/
|
@mkdir -p ~/.password-store/.extensions/
|
||||||
@cp sshkeys.bash ~/.password-store/.extensions/
|
@cp extension/sshkeys.bash ~/.password-store/.extensions/
|
||||||
@chmod +x ~/.password-store/.extensions/sshkeys.bash
|
@chmod +x ~/.password-store/.extensions/sshkeys.bash
|
||||||
@echo "Installation complete. You can now use 'pass-sshkeys'."
|
@echo "Installation complete. You can now use 'pass-sshkeys'."
|
||||||
10
README.md
10
README.md
|
|
@ -53,7 +53,7 @@ alias pass='PASSWORD_STORE_ENABLE_EXTENSIONS=true pass'
|
||||||
Import a single host:
|
Import a single host:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pass ssh import hostname
|
pass sshkeys import hostname
|
||||||
```
|
```
|
||||||
|
|
||||||
When importing a host, the extension automatically detects and handles ProxyJump configurations:
|
When importing a host, the extension automatically detects and handles ProxyJump configurations:
|
||||||
|
|
@ -65,7 +65,7 @@ When importing a host, the extension automatically detects and handles ProxyJump
|
||||||
Import all hosts from SSH config:
|
Import all hosts from SSH config:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pass ssh import-all
|
pass sshkeys import-all
|
||||||
```
|
```
|
||||||
|
|
||||||
### Export SSH Keys and Config
|
### Export SSH Keys and Config
|
||||||
|
|
@ -73,13 +73,13 @@ pass ssh import-all
|
||||||
Export a single host:
|
Export a single host:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pass ssh export hostname
|
pass sshkeys export hostname
|
||||||
```
|
```
|
||||||
|
|
||||||
Export all stored hosts:
|
Export all stored hosts:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pass ssh export-all
|
pass sshkeys export-all
|
||||||
```
|
```
|
||||||
|
|
||||||
### Direct Connection
|
### Direct Connection
|
||||||
|
|
@ -87,7 +87,7 @@ pass ssh export-all
|
||||||
Connect to a host using stored keys without importing:
|
Connect to a host using stored keys without importing:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
pass ssh connect hostname
|
pass sshkeys connect hostname
|
||||||
```
|
```
|
||||||
|
|
||||||
The connect command:
|
The connect command:
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,38 @@
|
||||||
|
PASSWORD_STORE_EXTENSION_COMMANDS+=(sshkeys)
|
||||||
|
|
||||||
|
__password_store_extension_complete_sshkeys() {
|
||||||
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
local subcommand="${COMP_WORDS[2]}"
|
||||||
|
|
||||||
|
# If we are completing the subcommand itself (at index 2)
|
||||||
|
if [[ $COMP_CWORD -eq 2 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "import import-all export export-all connect -v --verbose -h --help" -- "$cur"))
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If -v or --verbose is at index 2, we might be completing the subcommand at index 3
|
||||||
|
if [[ "${COMP_WORDS[2]}" == "-v" || "${COMP_WORDS[2]}" == "--verbose" ]]; then
|
||||||
|
if [[ $COMP_CWORD -eq 3 ]]; then
|
||||||
|
COMPREPLY=($(compgen -W "import import-all export export-all connect -h --help" -- "$cur"))
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
# The actual subcommand is at index 3
|
||||||
|
subcommand="${COMP_WORDS[3]}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# We are completing an argument for a subcommand
|
||||||
|
case "$subcommand" in
|
||||||
|
import)
|
||||||
|
# Suggest hosts from ~/.ssh/config
|
||||||
|
if [[ -f "$HOME/.ssh/config" ]]; then
|
||||||
|
local hosts=$(awk '/^[Hh][Oo][Ss][Tt][[:space:]]/{for(i=2;i<=NF;i++){if($i~/#/){break};if($i!="*"){print $i}}}' "$HOME/.ssh/config" | sort -u)
|
||||||
|
COMPREPLY=($(compgen -W "$hosts" -- "$cur"))
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
export|connect)
|
||||||
|
# Suggest hosts from the password store
|
||||||
|
local hosts=$(pass ls ssh 2>/dev/null | sed -e 's,^ssh/,,g' -e 's,/.*,,g' | sort -u)
|
||||||
|
COMPREPLY=($(compgen -W "$hosts" -- "$cur"))
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
@ -442,6 +442,20 @@ cmd_connect() {
|
||||||
ssh -F "$tmp_config" "$hostname"
|
ssh -F "$tmp_config" "$hostname"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Show help
|
||||||
|
cmd_help() {
|
||||||
|
cat <<-_EOF
|
||||||
|
Usage: pass ssh [-v|--verbose] import|import-all|export|export-all|connect [hostname]
|
||||||
|
|
||||||
|
Commands:
|
||||||
|
import - Import a host and its dependencies from ~/.ssh/config.
|
||||||
|
import-all - Import all hosts from ~/.ssh/config.
|
||||||
|
export - Export a host and its dependencies to ~/.ssh/config.
|
||||||
|
export-all - Export all hosts to ~/.ssh/config.
|
||||||
|
connect - Connect to a host using the stored keys.
|
||||||
|
_EOF
|
||||||
|
}
|
||||||
|
|
||||||
# Main command handler
|
# Main command handler
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-v | --verbose)
|
-v | --verbose)
|
||||||
|
|
@ -472,5 +486,8 @@ connect)
|
||||||
shift
|
shift
|
||||||
cmd_connect "$@"
|
cmd_connect "$@"
|
||||||
;;
|
;;
|
||||||
|
-h|--help|help)
|
||||||
|
cmd_help
|
||||||
|
;;
|
||||||
*) die "Usage: pass ssh [-v|--verbose] import|import-all|export|export-all|connect [hostname]" ;;
|
*) die "Usage: pass ssh [-v|--verbose] import|import-all|export|export-all|connect [hostname]" ;;
|
||||||
esac
|
esac
|
||||||
Loading…
Reference in New Issue