Thursday, April 10, 2025

How to Connect to a sudo User in WinSCP Without Knowing Their Password


In many Linux environments, you might have access to a privileged user (like podadmin) only through sudo — for example, from a user like uday via:

sudo su - podadmin

This works fine in a terminal (e.g., PuTTY), but what if you want to connect as podadmin using WinSCP — and you don’t know podadmin's password?

Here’s how you can do it.


🛠️ Problem Setup

  • You can log in as user, and from there sudo su - podadmin.

  • You do not have the password for podadmin.

  • You want to transfer files as podadmin using WinSCP.


✅ Solution: Use uday in WinSCP and Auto-Switch to podadmin

Step 1: Open WinSCP and Set Up a New Session

  1. In the Session tab:

    • File protocol: SCP

    • Host name: your server's IP or hostname

    • User name: user

    • Password: your uday password

  2. Click Advanced...

  3. Go to Environment > SCP/Shell

  4. Set Shell to:

    sudo su - podadmin
    
  5. Save the session and connect.


🔒 Optional: Enable Passwordless Sudo (for a smoother experience)

By default, WinSCP can't interactively enter a sudo password. To make it work, you can configure passwordless sudo access for user to become podadmin.

Steps:

  1. SSH into the server as root or a user with sudo access.

  2. Run:

    sudo visudo
    
  3. Add this line at the end:

    user ALL=(podadmin) NOPASSWD: ALL
    

Now, user can switch to podadmin without entering a password — perfect for automated tools like WinSCP.


🚀 Done!

You can now use WinSCP to connect as user, and it will automatically switch to podadmin on login. You’ll be able to access and transfer files as if you were podadmin, without needing their password.


No comments:

Post a Comment