Need to combine “Sudo” and “ScpTo” examples of JSch

℡╲_俬逩灬. 提交于 2019-12-10 12:16:02

问题


I'm unsuccessful with combining "Sudo" and "ScpTo" cases.

I noticed, that both work through "exec" channel.

Clean "ScpTo" case finishes with "Permission denied" message.

"Sudo" case

Channel channel = session.openChannel("exec");
((ChannelExec) channel).setCommand("sudo -S -u <supervisor> whoami");

works fine.

When I connect to my server through FarManager I write server option:

sudo su -l <supervisor> -c /usr/libexec/openssh/sftp-server

Also, I can run usual SFTP client like this:

sftp -s 'sudo su -l <supervisor> -c /usr/libexec/openssh/sftp-server'  "usual user"@"host"

and give put command.

But such option (-s) is not implemented in JSch.

How can I configure my case (Sudo & ScpTo) with JSch?


回答1:


In ScpTo.java example, there's this code:

String command="scp " + (ptimestamp ? "-p" :"") +" -t "+rfile;

Change that to:

String command="sudo su -l <supervisor> -c scp " + (ptimestamp ? "-p" :"") +" -t "+rfile;


来源:https://stackoverflow.com/questions/30494400/need-to-combine-sudo-and-scpto-examples-of-jsch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!