This is an old revision of the document!

How do I change user after login (e.g. su root)?

None of the protocols (SFTP, FTP and SCP) supported by WinSCP allow the user to be changed in the middle of file transfer session. You need to start the session with the correct user.

Advertisement

Direct Login

Easiest way is to allow direct login with the user account you need, if it is not allowed already. For accounts such as root, the direct login is typically disabled by default for security reasons. So when enabling it, have security in mind.

Particularly with SSH, you may want to keep password authentication (the most vulnerable one) disabled and use e.g. public key authentication instead. With OpenSSH server, you can do that by setting sshd_config keyword PermitRootLogin to without-password1.

Use sudo on Login

In some cases you may be able to use sudo command straight after login to change a user, before file transfer session starts.

FTP protocol does not allow this.

The SFTP and SCP protocols allow for this, but the actual method is platform dependant.

With SFTP protocol, you can use SFTP server option on SFTP tab of Login dialog to execute SFTP binary under different user. Under Unix/Linux with OpenSSH server, you can specify:

sudo su -c /bin/sftp-server

With SCP protocol under Unix/Linux server, you can specify following command as custom shell on the SCP/Shell tab of Login dialog:

sudo su -

Advertisement

However typically you will not be able to provide a password for su, see remote command execution limitations. So you may be able to do the above only if you are allowed to do sudo su without being prompted with password. See sudo documentation to learn how to do that. For example you can add following line to sudoers file (/etc/sudoers):

yourusername ALL=(ALL) NOPASSWD: ALL

Note that as WinSCP cannot implement terminal emulation, you need to have sudoers option requiretty turned off (what is default).

  1. Even more restrictive option forced-commands-only may work with SFTP protocol, but it has not been tested.Back

Last modified: by 82.153.174.10 – Currently locked by: 198.46.173.98