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-password
1.
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.
SFTP and FTP protocols do not allow this.
The SCP protocol allows for this (in the Options dialog, select Session, then look at the Protocol section in the pane to the right, and select SCP), but the actual method is platform dependant.
If you are connecting to a Unix/Linux server, you can specify following command as custom shell on the SCP/Shell tab of Login dialog (Environment > SCP/Shell):
/bin/bash -c 'sudo su -'
You can do this 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
Advertisement
Note that as WinSCP does not allocate TTY, you need to have sudoers
option requiretty
turned off (what is default).
- Even more restrictive option
forced-commands-only
may work with SFTP protocol, but it has not been tested.Back