sshj icon indicating copy to clipboard operation
sshj copied to clipboard

How to run SFTPClient as a sudo user

Open ajit-pawar-sp opened this issue 4 years ago • 4 comments
trafficstars

Hi,

I would like to use SFTP Client with the sudo user. The connected user will not have execute permission but through sudo user it can access sftp command.

Is that possible?

Thanks Ajit

ajit-pawar-sp avatar May 27 '21 13:05 ajit-pawar-sp

I'm not sure I understand the question. If you want to run SSHJ under a sudo user, just ensure that you fire up your java process as that user. If you want to assume a remote user, login as that specific user, contrary to scp, sftp is a separate server process which is either running or not. SCP starts up a remote listening process over the ssh connection

hierynomus avatar Nov 11 '21 09:11 hierynomus

This would require to start the SFTP subsystem on the server using sudo.

dkocher avatar Nov 11 '21 09:11 dkocher

They must be talking about wrapping sftp-server on the remote machine into sudo. Probably, it would require using exec channels instead of subsystems for SFTP. Also, a lot of problems arise with providing a password for sudo. Nevertheless, people say that it is possible, and that WinSCP is able to provide that, even though I don't see such feature in the WinSCP documentation.

vladimirlagunov avatar Nov 11 '21 09:11 vladimirlagunov

The subsystem process for sftp can be started with sudo E.g with golang sftp client https://github.com/kubernetes/kops/blob/master/util/pkg/vfs/sshfs.go#L81

could the same thing be achieved with sshj if there is a factory method for subsystem creation?

https://github.com/hierynomus/sshj/blob/master/src/main/java/net/schmizz/sshj/sftp/SFTPEngine.java#L69

organic-scholar avatar Jan 31 '22 21:01 organic-scholar