first, this is a security issue.
Here is a nice review article:
http://www.symantec.com/connect/articles/ssh-host-key-protection
Basically ssh servers (openssh-server) use keys to identify themselves and prevent others from mimicking them. A "man in the middle" might, for example, capture your user name and password.
You can fix it via several methods, I prefer
ssh-keygen -R server
Before you do that, however, you should check with the server sys admin to see if the (server) keys were changed.
For your scp error, you need to use the full path. My guess would be:
scp myfile user@server:/home/user_name/Folder
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
Best Answer
You have things in the right order from what I understand, the general way an scp is done is:
Judging by your question, you have a local file you want to send to the destination server. So you have the right syntax which is good!
If you're getting permission denied, then you're not using the correct username or something's amiss with the authentication. Most likely, it's because the sudo command only works locally, for starters, so it won't give you root on the remote box, so that's probably the problem. Make sure that the user you are logging in as on the remote server has write permissions to the location you're trying to write to.
If the problem is the destinationuser doesn't have access to that location without sudo, move the file to the destinationuser's home folder then sudo mv the file from the shell on the other server to put it in the right location.