Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using ssh keys with scp and ssh

Tags:

scp

ssh

ssh-keys

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] 
like image 805
user3721640 Avatar asked Jun 09 '14 08:06

user3721640


People also ask

Does SCP use SSH key?

The scp command uses SSH to transfer data, so it requires a password or passphrase for authentication.

Does SCP and SSH use same port?

By default, the SCP command uses the port 22 (SSH). In case the remote system has configured the SSH service to run on a different port, you still can use SCP followed by the -P flag to specify the port you need.

What is the difference between SSH and SCP?

The main dierence between SSH and SCP is that SSH is used for logging into remote systems and for controlling those systems while SCP is used for transferring files among remote computers in a network.


2 Answers

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.

like image 156
Mahattam Avatar answered Sep 19 '22 19:09

Mahattam


You can follow below procedure as well:

  1. Generate ssh key using below command
~]$ ssh-keygen 

It will ask you for details like file name, file location, passphrase etc.

  1. Make sure keep location and file name as default which will be
/home/user/.ssh/rsa_id 

After confirming passphrase, private and public key files will be created.

  1. Create file with name authorized_keys in same .ssh folder as in step 2. Copy contents of public key in this file.

You are done! Works for both ssh and scp the only password required will your passphrase (if you keep one).

like image 42
damndemon Avatar answered Sep 18 '22 19:09

damndemon