You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment this isn't possible because we request that the remote ssh server start an sftp-session for us.
What I think winscp is doing is starting a normal terminal session (without pty) then running sudo /usr/libexec/sftp-server which does essentially the same thing, although it does require that sudo for that account not ask for a password, or be configured to not ask for a password for that command.
If you like I can send you a branch which sort of does what I think winscp is doing and we can take it from there.
I've been looking at this today, and started out by looking at how this is handled when using the sftp cli. Seems like there are two ways to use sudo on sftp. Look at this stack exchange question for reference.
It works, but I would like to get some input and want to ask if this is something that would be considered as a PR. Both methods I've added could be implemented by users when they need such functionality, but it might save someone the time I've spent today looking into this.
1 - Modifying /etc/sshd_config
It seems like modifying the Subsystem sftp command is one way to go, but looking at it, it could also be that some would like to add a new Subsystem with sudo-prefix.
Don't know how likely it would be that someone would want to do this, but I've added the method NewSubsystemClient, that allows users to specify which subsystem to use.
2 - Specifying a subsystem command using the -s command line flag
Something like this: sftp -s "sudo /usr/lib/openssh/sftp-server" targethost.fqdn
Man states the following about -s
s subsystem | sftp_server
Specifies the SSH2 subsystem or the path for an sftp server on the remote host. A path is useful when the remote sshd(8) does not have an sftp subsystem configured.
I've added NewSubsystemCommandClient to allow users to specify a custom command to be used. This matches the WinSCP option and the sftp -s flag.
It would probably be better to make a sftp.WithSubsystem(…) and either (sftp.WithCommand(…) or sftp.WithSubsystemCommand) instead of having separate exported functions for each… but it also looks like the current design is 😬 not going to make that sort of a thing easy.
PS: The code looks good in general, just a few linting things I would address in a PR.
@puellanivis Yes, I don't see how that could be done in a simple way.
I also briefly thought about passing it as a ClientOption somehow, and pick that out in NewClient, but it just felt wrong, even tho ClientOptions are configuration of a client. And it might not even be possible.
One thing to consider is only adding the NewSubsystemCommandClient method (maybe give it a new name), as I think the other method is a bit contrived and not as useful.
On the other hand: I also think I've successfully made a third method for specifically supporting sudo with and without pwd, by reading from stderr and writing to stdin before passing the pipes on to NewClientPipe.
It could be that methods such as these should live outside this package, but maybe I could add NewSubsystemCommandClient it as an example for NewClientPipe?
maybe I could add NewSubsystemCommandClient it as an example for NewClientPipe
I mean, that’s a minimal addition that I think could definitely get off the ground faster than adding code. Something to have around while we discuss how to best implement it ourselves internally?
When I modify the /etc/sshd_config "Subsystem sftp sudo /usr/lib/openssh/sftp-server",the go sftp could have root privilege.But the ansible-playbook create remote dir couldn't work. my ansible config is remote_tmp = /tmp/.ansible/tmp.It returns : "msg": "Failed to set execute bit on remote files (rc: 1, err: chmod
Failed to set execute bit on remote files (rc: 1, err: chmod
My first thinking on this error report is that the OS is preventing you from setting the executable bit on any file that is underneath /tmp whether you’re root or not. This is a pretty normal security feature, in the same sort of idea as W^X that is: temporary writeable locations should not be executable to prevent arbitrary code execution.
Failed to set execute bit on remote files (rc: 1, err: chmod
My first thinking on this error report is that the OS is preventing you from setting the executable bit on any file that is underneath /tmp whether you’re root or not. This is a pretty normal security feature, in the same sort of idea as W^X that is: temporary writeable locations should not be executable to prevent arbitrary code execution.
When I change the dir to the /home , Is the same. I think Is the conflict with the ansible sudo and the golang sftp sudo.Maybe use NewSubsystemCommandClient could solve!
Activity
davecheney commentedon Jun 14, 2014
Hmm. Good question.
At the moment this isn't possible because we request that the remote ssh server start an sftp-session for us.
What I think winscp is doing is starting a normal terminal session (without pty) then running sudo /usr/libexec/sftp-server which does essentially the same thing, although it does require that sudo for that account not ask for a password, or be configured to not ask for a password for that command.
If you like I can send you a branch which sort of does what I think winscp is doing and we can take it from there.
eikenb commentedon Jan 14, 2017
@davecheney are you still working on this?
krilor commentedon Apr 10, 2020
@davecheney and @eikenb I've been looking into this today.
I've been looking at this today, and started out by looking at how this is handled when using the sftp cli. Seems like there are two ways to use sudo on sftp. Look at this stack exchange question for reference.
I've also started on a branch to solve it: https://github.com/pkg/sftp/compare/master...krilor:subsystem?expand=1
It works, but I would like to get some input and want to ask if this is something that would be considered as a PR. Both methods I've added could be implemented by users when they need such functionality, but it might save someone the time I've spent today looking into this.
1 - Modifying /etc/sshd_config
It seems like modifying the Subsystem sftp command is one way to go, but looking at it, it could also be that some would like to add a new Subsystem with sudo-prefix.
Like this
Don't know how likely it would be that someone would want to do this, but I've added the method
NewSubsystemClient, that allows users to specify which subsystem to use.2 - Specifying a subsystem command using the -s command line flag
Something like this:
sftp -s "sudo /usr/lib/openssh/sftp-server" targethost.fqdnMan states the following about -s
I've added
NewSubsystemCommandClientto allow users to specify a custom command to be used. This matches the WinSCP option and the sftp -s flag.It uses and "exec" request, rather than "subsystem". "subsystem" is reserved for predefined subsystems (https://tools.ietf.org/html/rfc4254#section-6.5)
Usage example
puellanivis commentedon Apr 11, 2020
It would probably be better to make a
sftp.WithSubsystem(…)and either (sftp.WithCommand(…)orsftp.WithSubsystemCommand) instead of having separate exported functions for each… but it also looks like the current design is 😬 not going to make that sort of a thing easy.PS: The code looks good in general, just a few linting things I would address in a PR.
krilor commentedon Apr 11, 2020
@puellanivis Yes, I don't see how that could be done in a simple way.
I also briefly thought about passing it as a ClientOption somehow, and pick that out in NewClient, but it just felt wrong, even tho ClientOptions are configuration of a client. And it might not even be possible.
One thing to consider is only adding the NewSubsystemCommandClient method (maybe give it a new name), as I think the other method is a bit contrived and not as useful.
On the other hand: I also think I've successfully made a third method for specifically supporting sudo with and without pwd, by reading from stderr and writing to stdin before passing the pipes on to NewClientPipe.
It could be that methods such as these should live outside this package, but maybe I could add NewSubsystemCommandClient it as an example for NewClientPipe?
puellanivis commentedon Apr 12, 2020
I mean, that’s a minimal addition that I think could definitely get off the ground faster than adding code. Something to have around while we discuss how to best implement it ourselves internally?
krilor commentedon Apr 12, 2020
Ok, I'll raise a PR, and we'll take it from there. Hopefully within a couple of days.
If anyone are interested, I've also just successfully implemented and tested a sudo version that handles password, nopasswd, lecture and no lecture.
NewSudoClienthere: https://github.com/krilor/gossh/blob/master/rmt/suftp/suftp.go#L85 Needs some cleanup, but hey - it works.lwx2615 commentedon May 11, 2022
When I modify the /etc/sshd_config "Subsystem sftp sudo /usr/lib/openssh/sftp-server",the go sftp could have root privilege.But the ansible-playbook create remote dir couldn't work. my ansible config is remote_tmp = /tmp/.ansible/tmp.It returns : "msg": "Failed to set execute bit on remote files (rc: 1, err: chmod
puellanivis commentedon May 11, 2022
My first thinking on this error report is that the OS is preventing you from setting the executable bit on any file that is underneath
/tmpwhether you’re root or not. This is a pretty normal security feature, in the same sort of idea as W^X that is: temporary writeable locations should not be executable to prevent arbitrary code execution.lwx2615 commentedon May 13, 2022
When I change the dir to the /home , Is the same. I think Is the conflict with the ansible sudo and the golang sftp sudo.Maybe use NewSubsystemCommandClient could solve!