Mat*_*att 3 python ssh paramiko fabric raspberry-pi
我正在尝试使用 Fabric 模块通过以太网通过 SSH 连接到子网上的 Raspberry Pi,但我不知道如何验证连接。
到目前为止我的代码如下
import fabric
c = fabric.Connection(host = "192.168.3.151", port = 22, user = "pi")
c.run("touch Desktop/new_file.txt")
Run Code Online (Sandbox Code Playgroud)
显然我没有在上面的代码中的任何地方输入我的密码“Raspberry”来验证 SSH 连接。我一直在尝试理解 Fabric 文档,但它有点超出我的范围,所以我希望有人能告诉我如何输入密码来验证连接(以及使用 验证任何命令sudo)。
谢谢!
好的,看起来您可以将选项传递给Connection将传递给的构造函数SSHClient.connect
c = fabric.Connection("192.168.3.151", port=22, user="pi", connect_kwargs={'password': 'raspberry'})
Run Code Online (Sandbox Code Playgroud)
请注意,以纯文本格式存储密码通常是一个坏主意,尤其是在代码中。
请参阅http://docs.fabfile.org/en/2.1/concepts/authentication.html以及http://docs.fabfile.org/en/2.1/concepts/configuration.html
| 归档时间: |
|
| 查看次数: |
6192 次 |
| 最近记录: |