Solved

Linux, scp and sshpass

Posted on 2013-12-20
1
1,990 Views
Last Modified: 2013-12-20
I am using RHEL 6.5

If I perform the following command:

# sshpass -p 'xxxx' scp /etc/hosts root@xxclnt16:/home/hosts
#

Open in new window


It does not return an error, but the file is never actually copied.

I understand the problem is that the site was not authenticated, as I receive the following error if I do not use sshpass:

# scp /etc/hosts root@xxclnt16:/home/hosts                   
The authenticity of host 'xxclnt16 (10.14.1.18)' can't be established.
RSA key fingerprint is ef:e3:f8:71:cf:47:8b:1c:df:fa:82:ce:48:2a:66:92.
Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'xxclnt16,10.14.1.18' (RSA) to the list of known ho...

Open in new window


Why doesnt the command with sshpass report an error.  This would be quite helpful.  Is there any way to get it to report an error

Thanks
0
Comment
Question by:Los Angeles1
1 Comment
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 500 total points
ID: 39732032
sshpass does not report error messages which go to the tty (the operation principle of sshpass is intercepting tty input/output), so you will not see any message (except for the "man-in-the middle" warning which does not go to the tty).

As far as I know the only way to deal with situations like yours is to inspect the returncode of sshpass.

Your particular problem should set a returncode of '6', so you could do

sshpass -p 'xxxx' scp /etc/hosts root@xxclnt16:/home/hosts

if [[ $? -eq 6 ]]; then
  echo "Host Key Unknown"
   # perform any desired action
fi


These are the returncodes of sshpass according to its manpage:
       
    1 Invalid command line argument
    2 Conflicting arguments given
    3 General runtime error
    4 Unrecognized response from ssh (parse error)
    5 Invalid/incorrect password
    6 Host public key is unknown. sshpass exits without confirming the new key.
The mentioned "man-in-the-middle" issue will produce a returncode of 255.
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question