Skip to content

[v1] add an example of running sftp-server through sudo - #688

Open
christhomas wants to merge 1 commit into
pkg:masterfrom
christhomas:example-sudo
Open

christhomas wants to merge 1 commit into
pkg:masterfrom
christhomas:example-sudo

Conversation

@christhomas

Copy link
Copy Markdown
Contributor

For #12.

As suggested in the thread there, this adds an example for NewClientPipe rather than new API: NewClient always requests the sftp subsystem, so to get the equivalent of WinSCP's sudo option or sftp -s "sudo /usr/lib/openssh/sftp-server", the example starts sftp-server with sudo on a session (an exec request instead of subsystem) and passes the session's pipes to NewClientPipe. It notes that sudo must not ask for a password and that the sftp-server path varies by system.

I checked the same code against a small in-process SSH server that runs the exec command (minus the sudo, which it can't run): the server receives sudo /usr/libexec/sftp-server and the client can read directories through it.

NewClient always requests the "sftp" subsystem. To get root access
like WinSCP's sudo option or `sftp -s "sudo .../sftp-server"`, start
sftp-server with sudo on a session and hand its pipes to
NewClientPipe.

@puellanivis puellanivis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I get an eye-tick thinking about demonstrating to people how to use a footgun…

@christhomas

christhomas commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

You wanna drop it and let them build it themselves :) I'm always quite amused when people use footguns, we can delete this PR if you want

@puellanivis

Copy link
Copy Markdown
Collaborator

I suppose that’s the thing about footguns… should one show people how it can be done safely, hoping they don’t use it wrong; or should one just not tell them to not stuff beans up their nose?

I think if we’re going to put in an example, it might be important to note the risks involved explicitly…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants