Search code examples
sshfabrictty

how does fabric execute commands?


i am wondering how does fabric execute commands.

Let's say I give him env.user=User, env.host=HOST. Then i ask him to sudo('ls') Is that equivalent to me typing in a shell : ssh User@host 'sudo(/bin/ls)' or it's more : ssh User@host in a first time, then sudo ls commande in a seconde time ?

I'm asking that because sometimes using a shell, if the TTY has a bad configuration (I am a bit blurry on this), ssh User@Host 'sudo /bin/ls' return : sudo: no tty present and no askpass program specified but you can first log in with ssh User@Host then sudo ls and it works.

I don't know how to replicate the no tty error, but I know it can occurs. Would this block the sudo commande from Fabric?


Solution

  • Basically how it works is:

    • First a connection is established (equivalent as doing ssh User@host)
    • Over this connection a command is executed as follows:

      sudo -S -p 'sudo password:'  /bin/bash -l -c "your_command"
      

      You can also allow Fabric not to request a pty with either pty=False argument, env.always_use_pty=False or --no-pty commandline option.