sshj icon indicating copy to clipboard operation
sshj copied to clipboard

Switching user before SCP file transfer

Open billy172 opened this issue 4 years ago • 2 comments
trafficstars

Hello Jeroen!

I'm trying to implement scenario:

  1. It needs to download a file from remote host via SCP
  2. To get access to it, I need to connect to remote host under user A, then switch to user B like "sudo su - B", for user A has no permission to read a file I need and user B has no permission to connect to that remote host.

It looks like a quite common case, but I can't make it working with SSHJ for I don't see an opportunity to call "sudo su - B" in SCPEngine before a file transfer starts.

I was trying to switch user for a Session before SCPEngine is created, but it always leads to "net.schmizz.sshj.common.SSHRuntimeException: This session channel is all used up" for session is not allowed to be reused.

I hope there is a way to do this trick, could you please advise?

billy172 avatar Dec 02 '20 20:12 billy172

+1

kaushalkumar avatar Aug 22 '21 04:08 kaushalkumar

You could take a look at how this is implemented in Overthere (https://github.com/xebialabs/overthere).

hierynomus avatar Aug 22 '21 12:08 hierynomus