Saturday, October 7, 2017

How to scp/ssh using private/public keys

Note: Below tested on CentOS/RedHat 7x

1. In source system generate keys for specific user:

ssh-keygen -t rsa -C "user@source-machine-name"



Enter file in which to save the key (/root/.ssh/id_rsa): filename_rsa
No Passprase Enter passphrase (empty for no passphrase): passphrase
Enter same passphrase again: passphrase


2. In destination system under /home/user create .ssh folder (owner user and rights 700), and after create FILE authorized_keys (inside .ssh folder) (chmod 644 chown user) and copy Public key from source system into this file.

3. In destination system:
service sshd restart

4.  SSH from source to destination


ssh -i id_rsa_user user@destination-machine-ip


5. SCP files from source to destination

scp -i id_rsa_user /path/test.txt user@destination-machine-ip:/destination-folder/


No comments:

Post a Comment