{"slug":"network-device-cli","title":"network-device-cli","summary":"Use when SSHing into a router, switch, or firewall CLI.","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-11-06T16:26:15.486866Z","repo":{"url":"https://github.com/Dandi41/ntnroute","stars":11,"forks":0,"license":"MIT","updatedAt":"2026-11-06T03:38:06Z"},"bodyHtml":"<hr>\n<h2>name: network-device-cli\ndescription: \"Use when SSHing into a router, switch, or firewall CLI.\"\nversion: 1.1.0\nauthor: Hermes Agent\nlicense: MIT\nmetadata:\nhermes:\ntags: [ssh, cisco, ios, network, legacy-crypto, cli]</h2>\n<h1>Network Device CLI (Cisco IOS and other appliances)</h1>\n<h2>When to Use</h2>\n<ul>\n<li>The user gives a host + credentials and asks for a command (ping, show) to be\nrun <strong>on</strong> the device — router, switch, firewall, appliance.</li>\n<li>An SSH attempt to network gear fails with <code>Permission denied</code> or\n<code>no acceptable kex algorithm</code>.</li>\n<li>You need device-side reachability (can the router reach 8.8.8.8?) rather than\nhost-side.</li>\n<li>A request wants device config <strong>changed</strong> (interface, VLAN, route, ACL), not\njust read — see \"Before a config change\" below.</li>\n<li>You are rebuilding a device-inventory / automation workflow that must survive\nsession resets — the inventory (hostname, ip, port, credentials, config_list,\ncheckpoint) belongs on disk, never in the conversation.</li>\n</ul>\n<p>Not for a Linux server over SSH — plain <code>ssh user@host</code> works there.</p>\n<p>Network gear is not a Linux box. It runs an exec-mode CLI with paging, restricted\nexec commands, and — on anything a few years old — SSH algorithms that modern\nOpenSSH disables by default. Follow this order; each step fails in a way that\nmisdiagnoses as \"wrong password\" if you skip it.</p>\n<h2>1. Confirm reachability, then read the banner</h2>\n<pre><code>ping -c1 -W2 &lt;host&gt;\nssh -v -o ConnectTimeout=10 -o StrictHostKeyChecking=no \\\n    -o UserKnownHostsFile=/dev/null &lt;user&gt;@&lt;host&gt; exit 2&gt;&amp;1 \\\n  | grep -iE \"remote software|kex: algorithm|Authentications that can continue\"\n</code></pre>\n<p><code>remote software version Cisco-1.25</code> plus <code>kex: algorithm: (no match)</code> means\nlegacy crypto, NOT bad credentials. Solve the crypto before you touch the\npassword — otherwise every auth attempt reports <code>Permission denied</code> and you burn\ntime guessing passwords that were right all along.</p>\n<h2>2. Force legacy algorithms per connection</h2>\n<p>Modern OpenSSH still <em>ships</em> these algorithms; it only stops offering them. So\nthe fix is flags on the invocation, not an install and not a config edit:</p>\n<pre><code>-o KexAlgorithms=+diffie-hellman-group14-sha1,diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1 \\\n-o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedAlgorithms=+ssh-rsa \\\n-o Ciphers=+aes128-cbc,3des-cbc -o MACs=+hmac-sha1 \\\n-o PreferredAuthentications=password -o NumberOfPasswordPrompts=1\n</code></pre>\n<p>Do <strong>not</strong> edit <code>/etc/ssh/ssh_config.d/*.conf</code> for this: it needs root, and it\nweakens every future SSH connection instead of one. Keep the legacy flags inside\nthe invocation (or a <code>Host</code> block in <code>~/.ssh/config</code> scoped to that IP).</p>\n<h2>3. Password auth without sshpass/expect</h2>\n<p><code>sshpass</code> is usually absent and installing it needs root. OpenSSH's own askpass\nhook works fine and keeps the password out of <code>argv</code> and out of logs:</p>\n<pre><code>cat &gt; /tmp/askpass.sh &lt;&lt;'EOF'\n#!/bin/bash\nprintf '%s\\n' \"$SSH_PROBE_PW\"\nEOF\nchmod +x /tmp/askpass.sh\n\nSSH_PROBE_PW=\"$PW\" SSH_ASKPASS=/tmp/askpass.sh SSH_ASKPASS_REQUIRE=force DISPLAY=:0 \\\n  ssh -tt &lt;legacy flags&gt; &lt;user&gt;@&lt;host&gt; '&lt;command&gt;'\n</code></pre>\n<p><code>SSH_ASKPASS_REQUIRE=force</code> is what makes it work without <code>setsid</code>. Do not put\nthe password inline in the script or on the ssh command line.</p>\n<h2>4. Issue commands the way the device accepts them</h2>\n<ul>\n<li><strong>One command per connection</strong> on IOS. A single string with IOS arguments\n(<code>ping 8.8.8.8 repeat 5 timeout 2</code>) is rejected as\n<code>Line has invalid autocommand \"…\"</code> — exec mode takes the bare form only\n(<code>ping 8.8.8.8</code>, default 5 packets). For arguments, drive an interactive\nsession instead of exec mode.</li>\n<li><strong>Hold the channel open.</strong> With <code>&lt; /dev/null</code> the session closes the moment\nauth completes and you get a truncated reply (a lone <code>!</code> from a 5-packet\nping). Pipe a sleep into it instead:\n<pre><code>{ sleep 25; } | ssh -tt &lt;flags&gt; &lt;user&gt;@&lt;host&gt; 'ping 8.8.8.8' 2&gt;&amp;1 | tr -d '\\r'\n</code></pre>\n</li>\n<li><strong><code>-tt</code></strong> allocates the PTY the CLI expects; without it IOS output arrives\nmangled or not at all. <code>tr -d '\\r'</code> afterwards makes the output readable.</li>\n<li><strong>Paging:</strong> <code>terminal length 0</code> as an exec command can drop the session.\nPrefer reading short <code>show</code> output, or set paging inside an interactive\nsession only.</li>\n</ul>\n<h2>5. Report the device's own verdict</h2>\n<p>Quote the summary line verbatim — <code>Success rate is 100 percent (5/5), round-trip min/avg/max = 8/36/91 ms</code>, <code>%SYS-5-CONFIG_I</code>, <code>state: up</code>. Do not\nparaphrase into your own numbers, and do not claim success without the device's\nline in the output.</p>\n<h2>6. Before a config change: plan, approval, checkpoint</h2>\n<p>Reading is cheap; writing is not. For anything that changes state:</p>\n<ol>\n<li>Read first. Pull the running config and the relevant <code>show</code> output before\nproposing a diff — never configure from memory of what the device \"should\"\nlook like.</li>\n<li>Present the plan before touching the device, and stop there. Five blocks,\nin this order: (a) what changes and why, in one short reason; (b) the exact\ncommand list, verbatim; (c) the exact rollback command list; (d) the read-only\ncommand that will verify it afterwards plus the output/state you expect;\n(e) risk — which lines can cut you off, and why they do not here. A\nconfirmation that has not seen all five is not approval. This applies even\nwhen the user asked for the change in the same message, and even for one line.\nIf any line changes after approval, the old approval is void: re-present,\nre-ask.</li>\n<li>Save the pre-change running config to a file, and write the rollback script\nbefore applying. <code>references/config-change-safety.md</code> has the checkpoint →\napply → save → verify → rollback loop and the per-vendor command profiles.\nWhere the <code>network-change-management</code> skill is installed, run its rollback\ngenerator: <code>rollback_gen &lt;script&gt; --existing-config &lt;saved-config&gt;</code> drafts\nthe rollback — read it line by line and fill its\n<code># TODO restore from snapshot:</code> entries before use.</li>\n<li>Never send a command that can cut your own path back in: VTY/management\ninterface, <code>access-class</code>, default route, the interface you are connected\nthrough.</li>\n<li>Verify with the command promised in (d) once the change lands, and quote the\ndevice's own output line. The device echoing the config line is not\nverification; reading the resulting state back is.</li>\n</ol>\n<p>A change is not \"done\" because the device echoed the line. Re-read the running\nconfig and check the lines are actually present; a capture that shows no error is\nweaker evidence than a captured config containing the line.</p>\n<h2>7. Persistent interactive session (OpenSSH)</h2>\n<p>One-shot OpenSSH suits a single <code>show</code>. For a session that enters <code>enable</code> with a\nsecret and then runs a dozen commands, hold one PTY open instead of spawning an\nssh per command — the engine's own technique, no paramiko, no Python:</p>\n<pre><code>SSH_ASKPASS=/tmp/askpass SSH_ASKPASS_REQUIRE=force setsid \\\n  ssh -tt -o KexAlgorithms=+diffie-hellman-group14-sha1 \\\n      -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedAlgorithms=+ssh-rsa \\\n      -o Ciphers=+aes128-cbc -o MACs=+hmac-sha1 admin@10.0.0.5 &lt; plan\n</code></pre>\n<ul>\n<li><code>SSH_ASKPASS</code> + <code>setsid</code> (no controlling tty) supplies the password without\nsshpass; <code>SSH_ASKPASS_REQUIRE=force</code> needs OpenSSH 8.4+.</li>\n<li><code>-tt</code> forces the PTY so the device prints prompts; feed a paced plan of\n<code>delay&lt;TAB&gt;command</code> pairs on stdin — pause after connect, then one line at a\ntime. Pacing replaces read-until-idle: gear that pauses mid-output otherwise\ngets the next command typed into the middle of the previous one.</li>\n<li>On a piped PTY the prompt is never a standalone line: the device prints it and\nthe next command lands on the same line (<code>R2&gt;show clock</code>). Parse prompts as a\nline <em>prefix</em> (<code>^[A-Za-z0-9_.-]{1,63}[&gt;#]</code>), not a line suffix.</li>\n<li>Disable paging first (<code>terminal length 0</code>); a stray <code>--More--</code> cannot be\nanswered from a pipe.</li>\n<li><code>enable</code>: send <code>enable</code>, pause, send the secret, then confirm the prompt ends\nin <code>#</code>. Report the prompt you actually saw rather than assuming the enable\nsucceeded.</li>\n<li>Keep the password out of <code>argv</code> — the askpass helper reads it from the\nenvironment.</li>\n</ul>\n<p><code>scripts/ios_session.sh</code> is this session shape as a runnable CLI (same flags as\nthe old paramiko version: <code>--host --user --password --secret --cmd --show-config --paging</code>).</p>\n<h2>Credential parsing pitfall</h2>\n<p>Credentials arrive as run-together prose: <code>user admin pass S3cr3t! secret en4ble!</code> is\nuser <code>admin</code>, <strong>password <code>S3cr3t!</code></strong>, and <code>en4ble!</code> is the <em>enable secret</em> (privileged\nexec password) — not a passphrase with spaces. Try the whole string, then the\nsingle token, and report which one authenticated rather than silently using it.\nA Cisco banner plus a rejected multi-word password is the signal that you split\nthe string wrong.</p>\n<h2>Supporting files</h2>\n<ul>\n<li><code>scripts/legacy-ssh.sh</code> — wraps the flags, askpass, and hold-open stdin so a\none-shot command works first try.</li>\n<li><code>scripts/ios_session.sh</code> — persistent OpenSSH PTY session (enable, paging off,\nread running config) as a runnable CLI.</li>\n<li><code>references/config-change-safety.md</code> — checkpoint → apply → save → verify →\nrollback loop, rollback-script rules, and per-vendor command profiles.</li>\n</ul>\n","files":[{"path":"references/config-change-safety.md","sizeBytes":6018,"isText":true},{"path":"scripts/ios_session.sh","sizeBytes":6348,"isText":true},{"path":"scripts/legacy-ssh.sh","sizeBytes":1489,"isText":true},{"path":"SKILL.md","sizeBytes":9197,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"notes-only","suspicious":0,"notes":2,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-11-06T16:26:24.803419Z","sha256":"F2BD037203DEB74760C836A36A940A51F26F114F0A6F0E85D67E7C53F89E7D77","sizeBytes":11143},"review":null,"source":{"repositoryUrl":"https://github.com/Dandi41/ntnroute","path":"skills/network-device-cli","license":"MIT","commit":"aeff5d40b773948bfba2f2e967541195fde0973b","subtreeSha":"C87FAB1C902E00C8CFF8DB529F541CDD7172BBF8B1E38B492B1403A0B4F995A8","lastSyncedAt":"2026-11-06T16:26:15.301943Z"},"reviewedAt":"2026-11-06T16:27:14.377331Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/Dandi41/ntnroute/tree/main/skills/network-device-cli"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install dandi41-ntnroute@llmmart"},{"target":"git","command":"git clone https://github.com/Dandi41/ntnroute.git"}]}