Repository navigation
Pre Connect Hooks
github-actions[bot] edited this page Sep 28, 2026
·
2 revisions
Run custom local commands or scripts automatically before connecting to an SSH host.
- Triggering corporate VPN connection scripts before dialing private IP ranges
- Sending Wake-on-LAN (WOL) magic packets to spin up remote bare-metal hosts
- Refreshing short-lived cloud credentials or MFA tokens (AWS SSM, Cloudflare Access, Okta)
Pre-connect hooks are configured directly in SSH config comments using # pre-connect: or # hook::
Host vpn-internal # pre-connect: /usr/local/bin/vpn-connect.sh %h
HostName 10.10.0.50
User devops
Host workstation-lab
# hook: wakeonlan 00:11:22:33:44:55
HostName 192.168.1.105
User adminneossh --pre-connect "vpn-up.sh %h" -c my-serverEdit a server (e) and configure the pre-connect command in the form.
Hook commands support token substitution:
| Token | Value |
|---|---|
%h |
Remote Hostname / IP address |
%p |
Remote SSH Port |
%r |
Remote User |
%n |
Server Alias |
%% |
Literal %
|
neossh also sets context environment variables before running hooks:
| Variable | Value |
|---|---|
NEOSSH_ALIAS |
Server alias |
NEOSSH_HOST |
Remote hostname |
NEOSSH_PORT |
Remote SSH port |
NEOSSH_USER |
Remote username |
If the pre-connect hook exits with a non-zero exit code, the SSH connection is safely aborted and the error output is reported in the TUI.
# VPN connection before accessing private network
Host private-server # pre-connect: /opt/vpn/connect.sh %h
HostName 10.0.0.42
User admin
# Wake-on-LAN for bare-metal host
Host homelab
# hook: wakeonlan AA:BB:CC:DD:EE:FF && sleep 10
HostName 192.168.1.100
User root
# AWS SSO token refresh
Host aws-bastion # pre-connect: aws sso login --profile %n
HostName bastion.aws.internal
User ec2-userneossh is an actively maintained continuation of lazyssh by Adembc. Licensed under Apache-2.0.