0

Hi I am writing a bit of python which runs command line commands. These commands then require a password and it doesnt seem to be working properly. Here is a code example:

os.system('git fetch --all')
os.system('password')
os.system('git reset --hard origin/dev')

so after running get fetch -all it requires a password and I was wondering how to enter that? I understand why my code isn't working, I am guessing it isn't entering the password, it is trying to run a new command password which obviously doesn't make sense.

I imagine it is something simple but I just cant seem to figure it out I appreciate any help :)

Luke Rayner
  • 391
  • 6
  • 20
  • You maybe should visit this [question](https://stackoverflow.com/questions/11506124/how-to-enter-command-with-password-for-git-pull). I will mark this as duplicate. – Sven-Eric Krüger Feb 09 '18 at 12:12
  • Possible duplicate of [How to enter command with password for git pull?](https://stackoverflow.com/questions/11506124/how-to-enter-command-with-password-for-git-pull) – Sven-Eric Krüger Feb 09 '18 at 12:13
  • I am using a ssh key and I have tried everything to store the passphrase but it doesn't seem to work that why I am trying to go down this route. Do you know how to enter a password in the command line? – Luke Rayner Feb 09 '18 at 12:15
  • Did you read about the credentials?... By the way `'password'`is not a safe password. Posting it here is even more unsafe... – Sven-Eric Krüger Feb 09 '18 at 12:23
  • @SvenKrüger `'password'` was just a dummy thats why I used it :) and yeah I have tried that it doesnt work – Luke Rayner Feb 09 '18 at 12:26
  • can we forget I am running a git command and pretend its another command which requires a password. How would I enter it in the command line? – Luke Rayner Feb 09 '18 at 12:28
  • Like `sudo`? Did you try `gitpython`?... This package has a method for handling ssh-passwords, see [Documentation](http://gitpython.readthedocs.io/en/stable/tutorial.html#handling-remotes). It is available on pypi. – Sven-Eric Krüger Feb 09 '18 at 12:33

1 Answers1

0

You need to understand how the program expects to receive the password.

In absence of any command line options the program would normally expect it on stdin. You therefore need to start the process and use the stdin pipe to send the password.

Regarding passphrases on SSH keys you can use ssh-agent and ssh-add to avoid this extra problem.

mjr104
  • 193
  • 1
  • 4