Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access to a remote server using Paramiko with a public key-file

I need to connect to a remote server without the use of a password but using a public keyfile using the Python module Paramiko.

How can I do this?

like image 214
nour Avatar asked Dec 17 '25 20:12

nour


1 Answers

Use key_filename argument of SSHClient.connect:

import paramiko
 
ssh = paramiko.SSHClient()
ssh.connect("example.com", username="user", key_filename="mykeyfile")

Though you need private key file for that. You cannot authenticate with public key file.


You will also need to verify the host key:
Paramiko "Unknown Server"

like image 172
Martin Prikryl Avatar answered Dec 19 '25 11:12

Martin Prikryl