• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Solaris : How to automate scp transfer (using passwordless ssh)

by admin

Because Secured Copy (SCP) is part of a suite of tools available with Secure Shell (SSH), you must first configure passwordless SSH before you can utilize the same for SCP. Authentication is checked against public key pairs for known hosts, instead of user id and password. Once you have SSH successfully configured to authenticate without a password, you can then utilize unprompted login with a secure copy.

Configuring passwordless scp from host A to host B

1. Host A: Generate Key-pair using the following command. Accept the default filename without entering a pass phrase. If asked for passphase press enter twice.

# ssh-keygen -t rsa

2. This above command will create two new files ( Public and Private RSA keys ) under the $HOME/.ssh/* of the user who fired the command.

id_rsa ( Private Key)
id_rsa.pub ( Public Key)

3. For ease in later identification, it is advisable to rename id_rsa.pub to a unique file name representing the system for which the key was created on because later you will copy this file to the other host you want to connect to (hostB). You will want to copy the file without overwriting the id_rsa.pub file for Host B. For Example – my hostname is hostA. So, on Host A :

# cd $HOME/.ssh
# mv id_rsa.pub id_rsa.pub-hostA

4. Copy the local public key to the remote host (HostB):

# scp $HOME/.ssh/id_rsa.pub-hostA hostB:$HOME/.ssh/id_rsa.pub-hostA

If this is your first time using ssh to connect to host B, you will receive the following message:

The authenticity of host 'hostB' can't be established.
RSA key fingerprint in md5 is: 62:84:2f:30:0b:8e:5a:28:d4:79:0f:c1:ed:c3:ab:d2
Are you sure you want to continue connecting(yes/no)?yes
Warning: Permanently added 'hostB,192.168.10.100' (RSA) to the list of known hosts.

You will need to enter the user’s password this one time only. Then, the file will be copied to host B’s .ssh directory.

5. Append your unique public key file to the public key file “authorized_keys” which creates the authorized_keys file in hostB’s .ssh directory, if it does not get created automatically with the next step. For Example, On hostB:

# touch $HOME/.ssh/authorized_keys
# cat $HOME/.ssh/id_rsa.pub-hostA >> $HOME/.ssh/authorized_keys

Host B’s .ssh directory should now look like this:

-rw-r--r-- 1 admin admin 225 Aug 3 12:51 authorized_keys
drwx------ 2 admin admin 512 Aug 3 12:51 .
-rw-r--r-- 1 admin admin 225 Aug 3 12:44 id_rsa.pub-suntime
-rw-r--r-- 1 admin admin 229 Aug 3 12:40 known_hosts
-rw------- 1 admin admin 883 Aug 3 12:39 id_rsa
-rw-r--r-- 1 admin admin 225 Aug 3 12:39 id_rsa.pub
drwxr-xr-x 114 admin admin 7680 Aug 3 12:39 ..

Verify

To verify if everything is working as expected, simply scp any file from hostA to hostB. You should not be prompted for password for the transfer.

# scp /tmp/testfile hostB:/tmp/testfile
testfile              100% |*****************************|     0       00:00

Filed Under: Solaris

Some more articles you might also be interested in …

  1. Understanding Special Permissions (setuid, setgid, sticky bit) in Solaris
  2. SVM : How to set boot device at OBP for mirrored root disk
  3. Script to label multiple disks in Solaris
  4. How to Configure iSCSI targets on Solaris 10
  5. How to Use the ‘truss’ Command for Program and Error Analysis in Solaris
  6. Resolving File System Full Situations in Solaris
  7. M4000 / M5000 : How to assign IP address to XSCFU
  8. How to force a crash dump on T1000/T2000 servers from ALOM
  9. Script for finding the process using a specific port in Solaris
  10. Solaris : How to start syslogd in debug mode

You May Also Like

Primary Sidebar

Recent Posts

  • diffstat: Create a histogram from the output of the diff command
  • diffoscope: Compare files, archives, and directories
  • diff-pdf: Tool for comparing two PDFs
  • dict: Command line dictionary using the DICT protocol

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright