Paramiko ssh 连接没有密码 [英] Paramiko ssh connection without password
问题描述
目前我正在通过在 ssh.connect 中提供密码从我的 Windows 桌面登录到 Unix 服务器.有没有办法避免提供密码?
Currently I am logging in to the Unix server from my Windows desktop by giving a password in ssh.connect. Is there a way I can avoid giving the password?
import paramiko
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('ltc02.force.com',username = 'user',password = 'pwd')
stdin,stdout,stderr = ssh.exec_command("pwd")
感谢您的支持.
推荐答案
是的,您可以使用没有密码的私钥进行公钥身份验证.
Yes, you can use public key authentication using a private key that has no password.
一般过程是您使用
ssh-keygen -t rsa
ssh-keygen -t rsa
然后你把你的公钥上传到服务器,复制粘贴到:
Then you upload your public key to the server, copy paste it into :
.ssh/authorized_keys
.ssh/authorized_keys
.ssh 目录将位于您在服务器上的用户主目录中.
The .ssh directory will be located in your user home directory on the server.
当然,因为您的私钥没有密码,所以您需要确保采取足够的措施来保护它.
Of course, because your private key has no password you need to ensure you take adequate steps to protect it.
请注意,这不是 Python 特定的答案.SSH 公钥是一个标准过程,使用的密钥是标准的 RSA(或 DSA)密钥.因此,您应该能够以您选择的任何语言进行 SSH 公钥身份验证.
Note that this is not a Python specific answer. SSH Public Key is a standard process and the keys uses are standard RSA (or DSA) keys. So you should be able to do SSH public key authentication in any language of your choice.
这篇关于Paramiko ssh 连接没有密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!