'Switch user using sudo via SSH in R
im using the SSH package in R.
Im trying to switch the user after i have successful opened up a session using the ssh_connect function, the documentation isnt clear to me.
The vignettes reads "Note that the exec functions are non interactive so they cannot prompt for a sudo password. A trick is to use -S which reads the password from stdin:"
command <- 'echo "mypassword!" | sudo -s -S apt-get update -y'
out <- ssh_exec_wait(session, command)
iv tried the following:
ssh_exec_wait(session, c('echo "mypassword!" | sudo -S su - user2'))
but it just outputs the following in the console and doesnt change the user:
"[sudo] password for user1:"
what am i doing wrong here?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
