简体   繁体   English

在IPython笔记本中请求密码

[英]Requesting password in IPython notebook

I have an IPython notebook which accesses data via SSH using encrypted ssh key file. 我有一个IPython笔记本,它使用加密的ssh密钥文件通过SSH访问数据。 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. 我可以使用input来从用户提示读取密码,但在这种情况下,密码在屏幕上可见。 Is there a way to securely obtaining password? 有没有办法安全地获取密码?

You should import the getpass module, then call getpass.getpass . 您应该导入getpass模块,然后调用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. 请注意,在旧版本中,输入密码的字段可能不会出现在IPython Notebook中,而是出现在终端/命令提示符窗口中。 In the latest versions of Jupyter Notebook, however, the prompt will appear in the Notebook itself. 但是,在最新版本的Jupyter Notebook中,提示将出现在Notebook本身中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM