[英]Python - How do I authenticate SSH connection with Fabric module?
I'm trying to SSH into a Raspberry Pi on a subnet via ethernet using the Fabric module but I can't figure out how to authenticate the connection. 我正在尝试使用Fabric模块通过以太网SSH连接到子网上的Raspberry Pi,但我无法弄清楚如何验证连接。
My code so far is as follows 到目前为止,我的代码如下
import fabric
c = fabric.Connection(host = "192.168.3.151", port = 22, user = "pi")
c.run("touch Desktop/new_file.txt")
Obviously I haven't put in my password, "Raspberry", anywhere in the above code to authenticate the SSH connection. 显然我没有在上面的代码中的任何地方输入我的密码“Raspberry”来验证SSH连接。 I've been trying to understand the Fabric documentation but it's a little beyond me so I'm hoping someone can tell me how to input the password to authenticate the connection (and also authenticate any commands using sudo
). 我一直在努力理解Fabric文档,但它有点超出我的范围,所以我希望有人可以告诉我如何输入密码来验证连接(并使用sudo
验证任何命令)。
Thanks! 谢谢!
Okay, it looks like you can pass options to the Connection
constructor that will be passed on to SSHClient.connect
好的,看起来您可以将选项传递给将传递给SSHClient.connect
的Connection
构造SSHClient.connect
c = fabric.Connection("192.168.3.151", port=22, user="pi", connect_kwargs={'password': 'raspberry'})
Note it's generally a bad idea to store your passwords in plain text, especially in code. 请注意,以纯文本格式存储密码通常是个坏主意,尤其是在代码中。
See http://docs.fabfile.org/en/2.1/concepts/authentication.html as well as http://docs.fabfile.org/en/2.1/concepts/configuration.html 请参阅http://docs.fabfile.org/en/2.1/concepts/authentication.html以及http://docs.fabfile.org/en/2.1/concepts/configuration.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.