Paramiko ssh connection without password

允我心安 提交于 2019-12-11 11:51:57

问题


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")

Thanks for your support.


回答1:


Yes, you can use public key authentication using a private key that has no password.

The general process is you create a new key on the client machine using

ssh-keygen -t rsa

Then you upload your public key to the server, copy paste it into :

.ssh/authorized_keys

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.

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.



来源:https://stackoverflow.com/questions/28344109/paramiko-ssh-connection-without-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!