ssh-connection-management
Skill10 starsChanged 4 months agoApache-2.0View on GitHub
Guides on establishing persistent master SSH multiplexing sockets at ~/.ssh/sockets/<TARGET_NAME>.sock using ssh -f -N -M -S, testing connection liveness, removing stale control sockets, and recreating sockets following user group modifications like docker usermod updates.
- Reads credentials
1 other project uses a version of this, 1 of them edited.
Adopted by
Most recently taken up by
- GoogleCloudPlatform/gcsfuseedited, first seen Oct 12, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 1
- GoogleCloudPlatform/gcsfuse★ 2.3k62% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository9 other files it gives its agents.
- npi/.agents/AGENTS.mdAGENTS.md
- analysis-report-generationSkill
- benchmark-build-setupSkill
- benchmark-suite-executionSkill
- bucket-creationSkill
- conformance-testingSkill
- gke-e2e-testingSkill
- remediation-advisorSkill
- run-gcsfuse-npiSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 42
Ensure local socket directory exists:
- Distinctive: line 49
Before starting a master connection, perform a non-destructive liveness check and remove socket files only if the master process is …
- Distinctive: line 75
Test remote command execution over the master socket:
- Very specific: line 82
If user permissions change on the remote VM (e.g., after adding the user to the docker group via usermod -aG docker):
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SSH Connection Management for GCSFuse NPI
This skill guides you through establishing, managing, and troubleshooting persistent SSH socket multiplexing connections to target GCE VMs or GKE intermediate controller VMs. Socket multiplexing speeds up command execution and maintains session resilience across automated workflow steps.
Prerequisites & Trigger Conditions
Prerequisites
- GCP Compute SSH Keys: Local SSH key pair present at
~/.ssh/google_compute_engine(or standard~/.ssh/id_rsa). - GCP Authentication: Local
gcloudauthenticated with compute viewer/admin permissions. - Network Reachability: Internal IP or hostname reachability to target VM (e.g.
nic0.<VM_NAME>.<ZONE>.c.<PROJECT_ID>.internal.gcpnode.com). - OpenSSH Client: Local OpenSSH client supporting ControlMaster options (
-M,-S).
Trigger Conditions
- Executed prior to running remote commands, setup scripts, conformance test suites, or benchmark runs on target GCE VMs or GKE intermediate VMs.
- Triggered when SSH connections fail due to stale socket files ("Control socket connect failed").
- Triggered when user permissions on target VM are modified (e.g., adding user to
dockergroup) requiring session group ID refresh.
Input/Output Contract
Inputs
- Target Connection Details:
- Target Name (
<TARGET_NAME>, e.g.,gce-c4-ssdfromtargets.json). - VM Name (
<VM_NAME>). - Zone (
<ZONE>). - GCP Project ID (
<PROJECT_ID>). - SSH User (
<SSH_USER>): Username used for SSH authentication. Resolved dynamically viaSSH_USER="${SSH_USER:-$(gcloud config get-value account 2>/dev/null | tr '@.' '_')}"or falling back to local OS username logic (local_user_google_com).
- Target Name (
- Socket Cache Directory:
~/.ssh/sockets/.
Outputs
- Active Master Socket File: Unix domain socket located at
~/.ssh/sockets/<TARGET_NAME>.sock. - Background SSH Process: Persistent background
ssh -f -N -Mprocess holding the master channel open.
Step-by-Step Procedure
Step 1: Create Socket Cache Directory
Ensure local socket directory exists:
mkdir -p ~/.ssh/socketsStep 2: Clean Up Stale Sockets
Before starting a master connection, perform a non-destructive liveness check and remove socket files only if the master process is unresponsive:
if ! ssh -O check -S ~/.ssh/sockets/<TARGET_NAME>.sock 2>/dev/null; then
ssh -O exit -S ~/.ssh/sockets/<TARGET_NAME>.sock 2>/dev/null || pkill -f "ssh -f -N -M -S ~/.ssh/sockets/<TARGET_NAME>.sock"
rm -f ~/.ssh/sockets/<TARGET_NAME>.sock
fiStep 3: Establish Master SSH Connection
Launch the persistent master SSH connection in the background (or persistent terminal), resolving SSH_USER dynamically:
SSH_USER="${SSH_USER:-$(gcloud config get-value account 2>/dev/null | tr '@.' '_')}"
ssh -f -N -M -S ~/.ssh/sockets/<TARGET_NAME>.sock -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/.ssh/google_compute_engine ${SSH_USER}@nic0.<VM_NAME>.<ZONE>.c.<PROJECT_ID>.internal.gcpnode.comKey options explained:
-f: Requests ssh to go to background just before command execution.-N: Do not execute a remote command (background connection mode).-M: Place the SSH client into master mode for connection sharing.-S ~/.ssh/sockets/<TARGET_NAME>.sock: Path to the control socket.-o IdentitiesOnly=yes -i ~/.ssh/google_compute_engine: Restrict authentication strictly to the specified compute key, avoiding identity rejection.-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null: Prevent interactive host key prompts.
Step 4: Verify Connection Liveness
Test remote command execution over the master socket:
ssh -S ~/.ssh/sockets/<TARGET_NAME>.sock -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/.ssh/google_compute_engine <SSH_USER>@nic0.<VM_NAME>.<ZONE>.c.<PROJECT_ID>.internal.gcpnode.com "echo 'Connection Alive'"Step 5: Refreshing / Recreating Sockets
If user permissions change on the remote VM (e.g., after adding the user to the docker group via usermod -aG docker):
- Gracefully terminate and remove the master socket after checking liveness:
ssh -O exit -S ~/.ssh/sockets/<TARGET_NAME>.sock 2>/dev/null || pkill -f "ssh -f -N -M -S ~/.ssh/sockets/<TARGET_NAME>.sock" rm -f ~/.ssh/sockets/<TARGET_NAME>.sock - Re-establish the master connection by repeating Step 3.
Failure Modes & Edge Cases
| Failure Scenario | Root Cause | Remediation / Recovery Action | ||
Control socket connect failed: Connection refused | Master SSH process died unexpectedly, leaving a dead socket file | Check socket liveness (ssh -O check -S ~/.ssh/sockets/<TARGET_NAME>.sock 2>/dev/null). If check fails, terminate process and delete stale socket file (`ssh -O exit -S ~/.ssh/sockets/<TARGET_NAME>.sock 2>/dev/null | pkill -f "ssh -f -N -M -S ~/.ssh/sockets/<TARGET_NAME>.sock" ; rm -f ~/.ssh/sockets/<TARGET_NAME>.sock`) and re-run master connection command. | |
Permission Denied (publickey) | SSH key ~/.ssh/google_compute_engine missing or expired GCP IAM SSH login credentials | Ensure -o IdentitiesOnly=yes -i ~/.ssh/google_compute_engine is passed. Run gcloud compute config-default-ssh-keys or gcloud compute ssh <VM_NAME> --zone=<ZONE> to refresh SSH keys. | ||
| Permission Group Refresh Delay (Docker) | Added user to docker group, but commands fail with permission denied while trying to connect to Docker daemon | Active SSH master session retains original group IDs. Terminate processes and remove sockets (pkill -f "ssh -f -N -M -S ~/.ssh/sockets/" ; rm -f ~/.ssh/sockets/*.sock) and start new master SSH socket. | ||
| Connection Drop / Network Disconnect | Remote VM rebooted or network path reset | Remove stale socket after checking with ssh -O check and re-establish master SSH connection. |
Verification Checks
- Local Socket Liveness Check: Confirm socket file exists and master process is alive:
ssh -O check -S ~/.ssh/sockets/<TARGET_NAME>.sock 2>/dev/null && echo "SOCKET_ALIVE" - Remote Echo Check: Confirm commands execute over multiplexed socket:
ssh -S ~/.ssh/sockets/<TARGET_NAME>.sock -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -i ~/.ssh/google_compute_engine <SSH_USER>@nic0.<VM_NAME>.<ZONE>.c.<PROJECT_ID>.internal.gcpnode.com "echo 'Connection Alive'"
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

