I have an IPython notebook which accesses data via SSH using encrypted ssh key file. I don't want to store the password in the notebook (nor in a separate file). I can use input in order to read the password from user prompt, but in this case the password is visible on the screen. Is there a way to securely obtaining password?
Asked
Active
Viewed 2.4k times
39
Boris Gorelik
- 27,385
- 36
- 123
- 169
1 Answers
75
You should import the getpass module, then call getpass.getpass.
import getpass
password = getpass.getpass()
Note that in old versions, the field where you enter the password may not appear in the IPython Notebook, but instead in your terminal/command prompt window. In the latest versions of Jupyter Notebook, however, the prompt will appear in the Notebook itself.
Mark Amery
- 127,031
- 74
- 384
- 431
DataSwede
- 4,711
- 8
- 38
- 63
-
this is constantly breaking in my experience. are there any alternatives to getpass? `testgetpassword = getpass("pw:")` "/opt/conda/lib/python3.6/getpass.py:91: GetPassWarning: Can not control echo on the terminal." – Lilith Schneider May 20 '21 at 17:43