Solved

Linux, scp and sshpass

Posted on 2013-12-20
1
1,958 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Weird Samba Connectivity Issue... 7 40
Remove a folder in Linux 9 105
High Bandwidth Usage 6 58
open source backup solution 1 29
rdate is a Linux command and the network time protocol for immediate date and time setup from another machine. The clocks are synchronized by entering rdate with the -s switch (command without switch just checks the time but does not set anything). …
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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

803 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