I had to copy a file between two hosts using scp and it prompted me for a password. scp does not allow you to specify the password in a command line. So, here is a quick way to establish a trust between two hosts.
We’ll assume that user-A on host-A is copying a file to the home folder of user-B on host-B.

On host-A, logged as user-A create the private/public key pair.

ssh-keygen

You should see something like this. Do not enter a passphrase.

Generating public/private rsa key pair.
Enter file in which to save the key (/home/user-A/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user-A/.ssh/id_rsa.
Your public key has been saved in /home/user-A/.ssh/id_rsa.pub.
The key fingerprint is:
98:c4:fe:aa:ff:aa:bb:11:b4:3b:7a:94:1f:ac:c4:0f user-A@host-A
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|       .  .  . o |
|  AA  . . C . Y  |
|       + =   o o |
|      . X   . o  |
|         . & . . |
|        Y o B o  |
|         + o = . |
|          V . .  |
+-----------------+

You’ll have two files (/home/user-A/.ssh/id_rsa) which is your private key and (/home/user-A/.ssh/id_rsa.pub) which is your public key. Copy your public key to host-B.

cat ~/.ssh/id_rsa.pub | ssh user-A@host-B 'cat >> ~/.ssh/authorized_keys'

If you get access denied, just copy id_rsa.pub file to the home folder of user-B on host-B under the .ssh folder and append it to the authorized_keys file. If this file doesn’t exist, create it.

Once you are done, you can copy the files from host-A using:

scp somefiles.* user-B@host-B:

More Posts


Powershell: Change SNMP settings on a remote server
November 24, 2014

Powershell: Change SNMP settings on a remote server

FreeBSD 10: postfix, dovecot, Roundcube, amavisd-new, spamassassin, clamav, pigeonhole
November 7, 2014

FreeBSD 10: postfix, dovecot, Roundcube, amavisd-new, spamassassin, clamav, pigeonhole

FreeBSD 10: icecast & ices
September 28, 2014

FreeBSD 10: icecast & ices

FreeBSD 10: SAMBA 4 as a domain controller running on a public IP (OpenVPN, BIND, pf)
July 27, 2014

FreeBSD 10: SAMBA 4 as a domain controller running on a public IP (OpenVPN, BIND, pf)