Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8621691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:52:33+00:00 2026-06-12T06:52:33+00:00

I recently started looking at fabric for remote deployment. I need to switch to

  • 0

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: 
[oldUser@ec2-111-11-111-111.compute-1.amazonaws.com] 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 oldUser@ec2-111-11-111-111.compute-1.amazonaws.com... 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:)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:52:34+00:00Added an answer on June 12, 2026 at 6:52 am

    Thanks J F Sebastian, There were couple of catches.

    1. Fabric makes connections lazily, so I had to make a dummy connection before invoking su to avoid context switch.
    2. Pwd need to be stored in global scope and so that it can be reused. Fabric doesnt put it in cache for overridden su command.

    Here is what ended up doing. Its working.

    pwd = None
    @hosts('myhost.com')
    def test():
        with cd('/home/oldUser/upgrade'):
            run('ls')  #This is to connect aggressively (instead of lazily)
            global pwd  #Change the scope of pwd
            if pwd is None:
                pwd = getpass.getpass('enter password for newUser')
    
            execute(su, pwd, 'newUser', 'touch x')  
            run ('ls')
            execute(su, pwd, 'newUser', 'rm x') 
            run ('ls')
    
    def su(pwd, user, command):
        with settings(
            password= "%s" % pwd,
            sudo_prefix="su %s -c " % user,
            sudo_prompt="Password:"
            ):
            sudo(command)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not an expert on VBA as I've recently started looking into this.
I just recently started looking into WatiN and was following the example from http://www.codeproject.com/KB/aspnet/WatiN.aspx
I am from J2EE background and recently started looking into .Net. I am wondering
I've installed PowerShell recently and one of the first things I started looking for
I recently started looking into building web applications using .NET MVC and I stumbled
I'm recently started to learn Twisted framework and now looking for some cheat sheets/reference
I've recently started down the road of programming in Objective-C, and I'm now looking
I started to program in Scala recently. I'm looking for a free Scala profiler.
I recently started working with a client that had an index.html file with this
I recently started a project in Symfony2 and I need to run some methods

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.