3

Is there any way to pass master password automatically/programmatically. as per the below code we have to input password manually, can we avoid this

import keyring 
keyring.set_password('testuser','testuser','testpassword')

test = keyring.get_password('testuser', 'testuser')
print(test)
athi
  • 41
  • 6

1 Answers1

0

If this is your personal computer then I would suggest that you store your master password in a secure location like /etc. For linux you can create a file like /etc/master_passwd.txt and store password in it (run the below command with sudo).

$ touch /etc/master_passwd.txt > your_password_here

Then in your python script you can get master password with:

with open('/etc/master_passwd.txt', 'r') as passwd_file:
    master_password = passwd_file.read()
Arpit Solanki
  • 9,567
  • 3
  • 41
  • 57
  • Adding password in to profile is not a secured or suggested way. to avoid this practice only we are trying to use password vaults. i am trying to find an unattended way to get the password to run scripts – athi Jun 16 '17 at 09:15
  • You have to store it somewhere. I suggest that you use any encryption algorithm to encrypt the password, store it in profile. And when you need it you can again decrypt it and use it. – Arpit Solanki Jun 16 '17 at 09:18
  • You are storing the master password in a secure location like /etc because only root can access those files so i think its secure – Arpit Solanki Jun 16 '17 at 09:19
  • Thanks for the response. I am trying create one UI for executing multiple scripts for automation and these scripts are required device login credentials and login credentials are stored in the keying. we can input the master password via UI. But i want to know the way to pass the master password as variable – athi Jun 16 '17 at 09:30
  • One way or another you have to store it somewhere. If you want it more secure you can create a file in any secure directory like /etc and store password in that file and in need you can parse that file so that it is secure more getting through environment variable. Let me know if want an update to the answer – Arpit Solanki Jun 16 '17 at 09:34
  • Can we pass master password as value ?from the file parser – athi Jun 16 '17 at 09:54
  • What i am asking is different , how to pass value master_password to master password prompt (Please enter password for encrypted keyring:) – athi Jun 16 '17 at 17:40
  • You don't have to pass it to prompt. Just put the value of master password that you are getting from file to wherever you want. You can put it in keyring.set method to get other passwords. – Arpit Solanki Jun 16 '17 at 17:45
  • `import keyring` `with open('/etc/master_passwd.txt', 'r') as passwd_file: master_password = passwd_file.read() print master_password keyring.set_password('testuser','testuser','testpassword') test = keyring.get_password( master_password,'testuser', 'testuser') print(test)` i tried this way but its failing – athi Jun 17 '17 at 16:07
  • TypeError: get_password() takes exactly 2 arguments (3 given) this is the error – athi Jun 17 '17 at 16:31
  • That's your script's problem. I would suggest next time you ask a question don't extend it too far like this. try to be specific about the problem – Arpit Solanki Jun 17 '17 at 16:33
  • I provided you the solution for what is asked – Arpit Solanki Jun 17 '17 at 16:34
  • this is not script problem get_password more than two arguments and solution is not helpful any way thanks for your support – athi Jun 17 '17 at 16:44
  • Yeah how will it be helpful when you change your requirements to too far and don't try to think about the provided solution. You have to apply the solution not blindly copy paste the code. I gave you the idea I am sure that a little knowledge of python would do here. – Arpit Solanki Jun 17 '17 at 17:04