I have an Ubuntu 16.04 server with SSH, I have configured a keypair so I can SSH on to a remote system with no password, this works fine.
I am trying to SCP from Local (system1) to ther remote (system2), the SCP works fine but asks for a password. I want to use the keypair for non-autheticated copying.
I have followed numerous guides from the web on how to do this, but it basically seems to boils down to the following:
scp -i <path the PRIVATE key file> filetocopy [email protected]:~
Everything I can find on the internet says this should work - but it keeps asking for the password for the remote (2nd) system, even though I know the keypair works OK because I can use it for SSH.
Annoyingly - the same command as above will work perfectly with no password request if run as root - either by way of 'sudo' or from an elevated terminal...
so:
sudo scp -i <path the PRIVATE key file> filetocopy [email protected]:~
Works fine, but:
scp -i <path the PRIVATE key file> filetocopy [email protected]:~
does not.
There are no files in the roots' .ssh folder except for the known_hosts files (i.e. no key files)
What should I do?
It seems like you have copied the
root
key to the remote server, while the regular user key wasn't copied correctly.ssh
andscp
should provide the same feedback (with the difference of login-into-remote-server vs. copy-file-into-remote-server)When the key-pair will be copied as required to the remote server, the
scp
command will be:In order to copy the user key to the remote server, you can use ssh-copy-id
Copy the key to a server
Once an SSH key has been created, the ssh-copy-id command can be used to install it as an authorized key on the server. Once the key has been authorized for SSH, it grants access to the server without a password.
Use a command like the following to copy SSH key:
This logs into the server host, and copies keys to the server, and configures them to grant access by adding them to the authorized_keys file. The copying may ask for a password or other authentication for the server.
Only the public key is copied to the server. The private key should never be copied to another machine.
Test the new key
Once the key has been copied, it is best to test it:
The login should now complete without asking for a password. Note, however, that the command might ask for the passphrase you specified for the key. Troubleshooting
You have to do these following things to do scp over ssh without password:
This will work, if you got any error please update.
I got this sorted - I removed all my keys and keyfiles from both systems and worked through the process of setting up new keyfiles and using ssh-copy-id to copy the files over. It now works great.
There must have been some obscure corruption in the authorizes_keys file maybe messing it up. Thanks again.