1

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?

3 Answers 3

3

It seems like you have copied the root key to the remote server, while the regular user key wasn't copied correctly.

ssh and scp 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:

scp local-file-name user@remote-host:/full/path/remote-file-name

In order to copy the user key to the remote server, you can use ssh-copy-id

Note: You should replace the mykey in the below command, with the filename of your key-file

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:

ssh-copy-id -i ~/.ssh/mykey user@host

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:

ssh -i ~/.ssh/mykey user@host

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

2
1

You have to do these following things to do scp over ssh without password:

ssh-keygen
[Enter]
[Enter]
[Enter]
cd ~/.ssh
ssh-copy-id -i id_rsa.pub username@serverip/hostname
scp username@serverip:/file/to/copy /directory/to/save

This will work, if you got any error please update.

0

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.

1
  • 1
    Thanks for sharing your solution :-) You can also 'accept' one answer and 'upvote' the helpful answers.
    – sudodus
    Oct 19, 2017 at 12:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .