How to change user in WinSCP?

I'm using WinSCP to access Unix computers. How can I change user after I have logged into a Unix server using WinSCP?

E.g. I have personal account in Unix computer A. I can log into this computer using PuTTY and then change user to root user

$sudo /usr/bin/su - rootuser

How can I do the same thing using WinSCP? I don't know the password for rootuser.


Solution 1:

I'm going to assume you can already sudo to the user in question ... ... in WinSCP setup for a new site:

  1. New Site
  2. Session: File protocol: SCP
  3. Session: host name: my-host-name
  4. Session: user name: MY-user-name
  5. CLICK Advanced... BUTTON
  6. Advanced: left-hand-navigator select SCP/Shell
  7. Advanced:Shell: MAGIC-HAPPENS-HERE The "pick list" for Shell has "Default" selected. You will enter TEXT here...

    /usr/bin/sudo -u TARGET-user-name -i

(above command varies by unix distro)

  1. NO-OTHER-CHANGES to the default settings, just select OK to close the Advanced window and save your changes.

..... this should be all you need!

Solution 2:

There is a FAQ for this question on WinSCP site:
How do I change user after login (e.g. su root)?

You need to specify the sudo command in WinSCP session settings, as a custom shell (if you are using SCP) or use the sudo in a custom SFTP server startup command (if you are using SFTP).

Though there are some limitations, notably that you need to configure the sudo not to require a password.

See the link for details.