This is an old revision of the document!

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

You cannot change a user in the middle of file transfer session with neither of protocols WinSCP supports (SFTP, FTP and SCP). So you need to start with the correct user straight away.

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

You can 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 does not allocate TTY, 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 martin – Currently locked by: 198.46.173.98