Unable to "sudo su" using WinSCP/Powershell

Advertisement

rakesh_r5
Joined:
Posts:
2

Unable to "sudo su" using WinSCP/Powershell

Hello,
I'm using Powershell/Winscp to write an automated script for deployment.
However, I'm facing a stumbling block when trying to "sudo su". Here are the steps I've donw:
1. /etc/sudoers: Commented the line Defaults requiretty
2. /etc/sudoers: Added <username> ALL=(ALL) NOPASSWD: ALL
3. In putty under SSH, I have added /bin/bash -c 'sudo su -'and it directly logs me in as root without asking for password.
The following is the snippet of the script. I have commented on the line of the script thats not working:
$session.open($sessionOptions);
Write-Host("Session established"); #works ok
$session.ExecuteCommand("ls -lrt"); #lists default users files
$session.ExecuteCommand("/bin/bash -c 'sudo su -'"); #Script hangs here

After about a minute, I get the following exception:
Error: Exception calling "ExecuteCommand" with "1" argument(s): "Timeout waiting for WinSCP to respond".

Am I doing something wrong here? Can you please throw some light on this? I'm using WinSCP v5.13

Regards,
Rakesh

Reply with quote

Advertisement

rakesh_r5
Joined:
Posts:
2

Actually it worked! I tried a different command and it lists me root's files:
$session.ExecuteCommand("sudo -- sh -c 'whoami; cd ~ ;pwd; ls -lrt'");
Output:
root
/root
-rw-------. 1 root     root     9813 Feb 26  2015 anaconda-ks.cfg
-rw-------. 1 root     root        0 May 29  2017 newpasswd.ldif

Thanks,
Rakesh

Reply with quote

Advertisement

You can post new topics in this forum