Reputation: 947
I am trying to copy few files to a target system using scp and then login to the system and install those files. I used scp and ssh commands here with ssh keys for passwordless authentication.
The ssh key was created on the source system as below. Is this the correct and secured way of creating an ssh key?
~]# ssh-keygen -t rsa -N "" -f ~/.ssh/mytest.key
The key was copied from the source to target system with executing below command.
~]# ssh-copy-id -i ~/.ssh/mytest.key
Now, the SSH login works fine without prompting for a password, however the scp is still not working.. it still prompts for a password. Should I specify the key path when using scp? If so how do I specify the keypath along with scp command?
Here is the ssh command used
~]# ssh -i ~/.ssh/mytest.key [email protected]
Upvotes: 69
Views: 188875
Reputation: 41
Just do this it works:
chmod 400 keyfile.pem
scp -i /path/to/key.pem file-name user@server-ip:/path/to/user/home
Upvotes: 3
Reputation: 5783
Assume your case for scp from 192.168.1.1 try below command.
scp -i ~/.ssh/mytest.key [email protected]:/<filepath on host> <path on client>
make sure the key file should have permission 600 or 400.
Upvotes: 138
Reputation: 9
First, change chmod of the file on the remote before scp....
sudo chmod 775 'file-name'
Upvotes: -2
Reputation: 23
another option to copy ssh key:
ssh-copy-id [email protected]
after that you can use scp:
scp ./file [email protected]:/path_on_host/
result:
[file] -transfer-> [192.168.1.1:/path_on_host/]
Upvotes: 0
Reputation: 346
You can follow below procedure as well:
~]$ ssh-keygen
It will ask you for details like file name, file location, passphrase etc.
/home/user/.ssh/rsa_id
After confirming passphrase, private and public key files will be created.
You are done! Works for both ssh and scp the only password required will your passphrase (if you keep one).
Upvotes: 3