WinSCP with sudo privileges on an Ubuntu server AWS 📊

28/01/2025 security 3 mins read
Table Of Contents

To run WinSCP with sudo privileges on an Ubuntu server, you can follow these detailed steps. This configuration allows you to access files and directories that require elevated permissions.

Prerequisites

  • Ensure you have WinSCP installed on your local machine.
  • You need to have access to an Ubuntu server (in this case, Ubuntu 24.04).
  • Your user account on the server must have the necessary permissions to use sudo.

Step-by-Step Guide

  1. Open WinSCP:

    • Launch the WinSCP application on your local machine.
  2. Access Site Manager:

    • Go to Session in the menu bar and select Sites followed by Site Manager.
  3. Edit Your Site Profile:

    • In the Site Manager window, select your existing site profile or create a new one.
    • Click on the Edit button.
  4. Open Advanced Settings:

    • In the Edit Site dialog, click on the Advanced… button located at the bottom.
  5. Configure SFTP Settings:

    • In the Advanced Site Settings window, navigate to Environment and then select SFTP from the left panel.
    • You will see a field labeled SFTP Server. Here, you need to enter the command that allows you to run the SFTP server with sudo privileges.
  6. Insert SFTP Server Command:

    • Enter the following command in the SFTP Server field:
      sudo su -c /usr/lib/sftp-server
    • Note: The path /usr/lib/sftp-server may vary based on your system configuration. You can verify the correct path by checking your SSH configuration file (/etc/ssh/sshd_config) for the line starting with Subsystem sftp.
  7. Save Your Changes:

    • Click OK to save your changes in the Advanced settings.
    • Then click Save in the Edit Site dialog.
  8. Connect to Your Server:

    • Now, return to the main WinSCP interface and click on Login to connect to your server using your configured profile.
  9. Verify Permissions:

    • Once connected, you should have access to directories that require root permissions, allowing you to upload or modify files as needed.

Additional Considerations

  • Make sure that your user has NOPASSWD access in the /etc/sudoers file for seamless operation without being prompted for a password when using sudo commands. This can be set with an entry like:

    username ALL=(ALL) NOPASSWD: ALL

    Replace username with your actual username.

  • If you encounter issues connecting or transferring files, ensure that your SSH configuration allows for passwordless authentication if required, and check for any restrictions in your firewall settings or SSH daemon configuration.

By following these steps, you should be able to successfully configure WinSCP to operate with sudo privileges on your Ubuntu server, enhancing your file transfer capabilities while maintaining security protocols.