简体   繁体   中英

SSH : Copy files without password when using public key authentication.

We have 2 Debian servers, one for testing and one for live. I have some scripts which should be executed to transfer data from live to test. For both the servers we use PublicKeyAuthentication where our id_rsa.pub's contents are added to authorized_keys on test server.

Even after doing this, everytime I initiate a transfer from one server to another, I am being asked for password.

I also tried calling ssh-copy-id, but that didn't help and all I got was a duplicate entry in authorized_keys.

Lastly when I try sshpass, I get the following message, and i cannot enter the password as its just a message.

sshpass -v -p 'PASS' ssh root@our_server
SSHPASS searching for password prompt using match "assword"
SSHPASS read: Enter passphrase for key '/root/.ssh/id_rsa': 

Any ideas? Thanks.

From the output of sshpass, it seams that it is asking for the password of the key, not the password for the server:

Enter passphrase for key '/root/.ssh/id_rsa'

Protecting your SSH-keys with a password is a good practice, but you can not fully automate things that way, as you discovered. Depending on your situation, you can do either of the following:

  • Use an SSH-agent. This is a daemon that will ask your password once, and keep the private key cached until you remove it. This still has the benefit that your SSH-key is stored password-protected on disk, but you can use it as a password-less key. This has the added benefit that you can forward SSH-agent over SSH: if you SSH from your machine to server A, and then further on to server B, this last connection can use the key stored on your machine (instead of having to copy your key to server A).

  • Remove the password from the key entirely (you can use ssh-keygen to change the password to be blank)

How do you execute data transfer? Is it scp? Check your system usernames, make sure public keys are installed to authorized_keys file for correct user.

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