I recently started looking at fabric for remote deployment. I need to switch to a diff user (from the one that I login as) and am not able to figure it out. Is it even possible, if so how? My current user doesnt have sudo
permissions.
I tried changing following environment variables
env.sudo_prefix = "su newUser -c "
env.sudo_prompt = "Password:"
But fabric does not wait for password input for 'newUser' and fails.
out: Password:
[[email protected]] out: su: incorrect password
Fatal error: sudo() received nonzero return code 1 while executing!
Requested: touch x
Executed: su newUser -c -u "root" /bin/bash -l -c "cd /home/oldUser/upgrade && touch x"
Aborting.
Disconnecting from [email protected]... done.
Update:
As J.F. Sebastian suggested, su newUser -c
works, but it prompts password for every command for every server, which kind of defeats the purpose of automation. Is there any way in Fabric to pass in same value based on prompt (in this case, its always Password:
)
sudo('su newuser')
– Tangleberryrun('su newuser -c command')
works as expected. What is your fabric version? – Tangleberryenv.password
in addition to yourenv.sudo_*
? Though fabric uses-S
in default sudo prefix i.e., it passes the password via stdin thereforesu
might not work if it reads the password from a tty directly. – Tangleberryenv.password
is for initial login. I am using it currently. – Sseenv.password
temporarily:with settings(password=newuser_password): sudo(command)
? – Tangleberry