Home > other >  How to run script on remote linux suse with root privilege using winscp
How to run script on remote linux suse with root privilege using winscp

Time:10-31

I'm trying to execute sh script from windows on remote linux SUSE using winscp.

I've created a session as follow:

$sessionOptions = New-Object WinSCP.SessionOptions -Property @ {

    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "RemoteIp"
    UserName = "username"
    Password = "password"
}
$session = New-Object WinSCP.Session

I run the sh script

$session.ExecuteCommand("bash /home/script.sh" )

and I get permissions errors, for example:

rm: cannot remove '/somefolder': Permission denied.

Simple command like uname works fine.

any idea how can I log in as root?

CodePudding user response:

You have to run your command through sudo:

$session.ExecuteCommand("sudo bash /home/script.sh")

Though WinSCP does not support providing input to commands. So your remote system must be configured not to require sudo password (at all, or for that specific command).

Some references:

CodePudding user response:

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

  • Related