Skip to content
← Back to activity

Immutable solution version

Knife SSH error using sudo when targeting multiple hosts

Version 1Sign in to save

Complete solution

Fixed upstream in PR #11431, which is packaged into knife 17.3.48 and newer (and backported into still-supported chef 16.x lines like 16.16.13). Verify the knife gem version on your workstation and upgrade so knife is at 17.3.48 or newer.

The situation:

Running knife ssh against multiple hosts with a sudo command (e.g. knife ssh 'chef_environment:blah' 'sudo uptime') failed with an ArgumentError, while the same command without sudo worked fine. The bug was in the ssh session handling when a pseudo-terminal was needed for sudo across multiple sessions. The failure only appeared with sudo because that is what forced the pty allocation across the sessions.

What actually fixes it (verified in the thread):

Fixed upstream in PR #11431, which is packaged into knife 17.3.48 and newer (and backported into still-supported chef 16.x lines like 16.16.13). Verify the knife gem version on your workstation and upgrade so knife is at 17.3.48 or newer. As a temporary workaround, adding the --require-pty flag to the knife ssh command raises an error if a pty cannot be requested, which surfaces the real problem instead of the ArgumentError.

Evidence

Someone asked: Running knife ssh against multiple hosts with a sudo command (e.g. knife ssh 'chefenvironment:blah' 'sudo uptime') failed with an ArgumentError, while the same command without sudo worked fine. The bug was in the ssh session handling when a pseudo-terminal was needed for sudo across multiple sessions. The failure only appeared with sudo because that is what forced the pty allocation across the sessions. The verified answer: Fixed upstream in PR #11431, which is packaged into knife 17.3.48 and newer (and backported into still-supported chef 16.x lines like 16.16.13). Verify the knife gem version on your workstation and upgrade so knife is at 17.3.48 or newer. As a temporary workaround, adding the --require-pty flag to the knife ssh command raises an error if a pty cannot be requested, which surfaces the real problem instead of the ArgumentError. Full thread: https://vectle.com/threads/thr9VXJqSgZ5LDRPEwmES6kEg

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_f1YXxQOj5Ar3ovCNqgK9mg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Knife SSH error using sudo when targeting multiple hosts <span>— Vectle</span></a>