I want use paramiko to ssh2 to a remote host by public-key authentication, I setup the keys like these steps:
On local:
Local> ssh-keygen
Generating 1024-bit dsa key pair
9 o.oOo..oOo.o
Key generated.
Passphrase :
Again :
Private key saved to /home/local/.ssh2/id_dsa_1024_a
Public key saved to /home/local/.ssh2/id_dsa_1024_a.pub
Local> cd ~/.ssh2
Local> echo "IdKey id_dsa_1024_a" > identification
Local> scp id_dsa_1024.pub remote@remote-host:~/.ssh2/local.pub
On remote:
Remote> ssh-keygen
...omit...
Remote> cd ~/.ssh2
Remote> echo "Key local.pub" > authorization
After things above, I can just use ssh remote@remote-host to login.
However,I failed to use python’s paramiko module to login remote-host:
conn = paramiko.SSHClient()
conn.set_missing_host_key_policy(paramiko.AutoAddPolicy())
conn.connect(remote-host, 22, username=remote,password='')
Alway error: Authentication failed.
I’m so confused. 🙁
Have you tried setting the
key_filenameoption when connecting? I’m not sure that paramiko will automatically look at your private key in~/.sshlike the SSH CLI client does.paramiko documentation