简体   繁体   中英

I can ssh in manually, but not from a script - Permission denied (publickey)

So I'm currently working on a load balancing python script. In this script I will need to update a file on a server. My plan is to have my python script call a bash script.

In that bash script I'd like to ssh into the server, execute an awk command on a file, then logout.

I can currently ssh into this server manually, because I've set up an ssh key (using Google Cloud Platform). But when I try to run a bash script that only executes

'ssh username@externalIP'

I get the error: Permission denied (publickey)

What am I missing here?

Why not use paramiko to connect via SSH? You can specify a key, as shown in this gist .

By using this, you can easily set which commands to execute on the server.

Probably your private key is in your home directory and python is spawning the bash process as a limited user, try changing your script to include the private key explicitly, if still doesn't work you will have to copy the key and change its permission

To explicitly add the private key:

ssh -i /path/to/private/key user@host

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM