更新时间:2022-05-30 21:45:06
ssh.connect()
接受一个关键字参数 pkey
,你可以用它来指定你的私人文件.
ssh.connect()
takes a keyword argument pkey
which you can use to specify your private file.
#get IP and username for remote access
IP = input("Enter host_server IP: ").split()
username = input("Enter username: ").split()
#create a file on host_server for file
file_a = open(date+"file.txt", "a") #ignore the date variable
file = str(date+"file.txt")
import paramiko
import os
privatekeyfile = os.path.expanduser('~/.ssh/id_rsa')
mykey = paramiko.RSAKey.from_private_key_file(privatekeyfile)
ssh.connect(IP[0], username = user[0], pkey = mykey)