I currently do the following from the command line:
$ ssh myuser@remote-server
password:
[myuser@remote-server ~]$ sudo su - dev_user
[dev_user@remote-server ~]$ whoami
dev_user
[dev_user@remote-server ~]$
No permission issue.
The myuser has enough permission to do what typed above, but it does not have permission to do sudo su -c whoami dev_user
I tried the following code
from fabric import Connection, task
@task
def abcd(ctx):
sudo_pass = getpass.getpass("What's your sudo password?")
config = Config(overrides={'sudo': {'password': sudo_pass}})
with Connection('dev-server', user='myuser', connect_kwargs={"password": sudo_pass}, config=config) as c:
c.sudo('/bin/bash -l -c whoami', user='dev_user')
I get the following output:
fab abcd
What's your sudo password?
[sudo] password: Sorry, user myuser is not allowed to execute '/bin/bash -l -c whoami' as dev_user on dev-server.
Is there a way to get Fabric to do what I did from the command line?
Editing the sudoers
file is not an option.
The remote server is Linux RH 7.6.