How to run SUDO command in WinSCP to transfer files from Windows to linux

LinuxSudoWinscp

Linux Problem Overview


I am trying to use WinSCP to transfer files over to a Linux Instance from Windows.

I'm using private key for my instance to login to Amazon instance using ec2-user. However ec2-user does not have access to write to the Linux instance

How do I sudo su - to access the root directory and write to the linux box, using WinSCP or any other file transfer method?

Thanks

Linux Solutions


Solution 1 - Linux

I know this is old, but it is actually very possible.

  • Go to your WinSCP profile (Session > Sites > Site Manager)

  • Click on Edit > Advanced... > Environment > SFTP

  • Insert sudo su -c /usr/lib/sftp-server in "SFTP Server" (note this path might be different in your system)

  • Save and connect

Source

AWS Ubuntu 18.04: enter image description here

Solution 2 - Linux

There is an option in WinSCP that does exactly what you are looking for:

enter image description here

enter image description here

Solution 3 - Linux

AFAIK you can't do that.
What I did at my place of work, is transfer the files to your home (~) folder (or really any folder that you have full permissions in, i.e chmod 777 or variants) via WinSCP, and then SSH to to your linux machine and sudo from there to your destination folder.

Another solution would be to change permissions of the directories you are planning on uploading the files to, so your user (which is without sudo privileges) could write to those dirs.

I would also read about WinSCP Remote Commands for further detail.

Solution 4 - Linux

Usually all users will have write access to /tmp. Place the file to /tmp and then login to putty , then you can sudo and copy the file.

Solution 5 - Linux

I just wanted to mention for SUSE Enterprise server V15.2 on an EC2 Instance the command to add to winSCP SFTP server commands is :

sudo su -c /usr/lib/ssh/sftp-server

I didn't have enough Reputation points to add a comment to the original answer but I had to fish this out so I wanted to add it.

Solution 6 - Linux

I do have the same issue, and I am not sure whether it is possible or not,

tried the above solutions are not worked for me.

for a workaround, I am going with moving the files to my HOME directory, editing and replacing the files with SSH.

Solution 7 - Linux

ssh to FreePBX and run the commands stated below in your terminal:

sudo nano -f /etc/sudoers.d/my_config_file

YourUserName ALL=(ALL) NOPASSWD:ALL

sudo systemctl restart sshd

Winscp:

under session login ==> Advanced ==> SFTP

Change SFTP Server to:

sudo /usr/libexec/openssh/sftp-server

Solution 8 - Linux

Tagging this answer which helped me, might not answer the actual question

If you are using password instead of private key, please refer to this answer for tested working solution on Ubuntu 16.04.5 and 20.04.1

https://stackoverflow.com/a/65466397/2457076

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPC2015View Question on Stackoverflow
Solution 1 - LinuxPelly BenassiView Answer on Stackoverflow
Solution 2 - LinuxEng.FouadView Answer on Stackoverflow
Solution 3 - LinuxIdosView Answer on Stackoverflow
Solution 4 - LinuxS AView Answer on Stackoverflow
Solution 5 - LinuxAnthony PercivalleView Answer on Stackoverflow
Solution 6 - LinuxNaresh AView Answer on Stackoverflow
Solution 7 - LinuxRonenView Answer on Stackoverflow
Solution 8 - LinuxSRiView Answer on Stackoverflow