scp with sshpass


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting scp with sshpass
# 1  
Old 09-20-2013
scp with sshpass

Hi!

I'm trying to copy a set of files from server1 to server2. I'm doing this from server3. Using the sshpass functionality, can I accomplish this?

This is what I have so far, but this doesn't work:

Code:
user@server3#~ sshpass -p 'password' scp user1@server1:/path/from/* user1@server2:/path/to/

Obviously, the 'password' is same for user1@server1 and user1@server2.

Thanks for your help in advance!
# 2  
Old 09-20-2013
You can:
  • use the ssh cat twice to copy files through your host, or
  • go to one end with sshpass ssh and sshpass scp that end locally, so you can embed two sshpass commands, each for one host, or
  • you can man up and get the PPK no-password access working, stop exposing passwords and failing security audits.
This User Gave Thanks to DGPickett For This Post:
# 3  
Old 09-20-2013
You do realize that your password is visible to the entire system when you do this, yes?

ssh makes it a pain to pass around password because doing so is a really bad idea.
# 4  
Old 09-20-2013
I have a regular copy I do between servers. So I just set up a public/private key pair to do the job. On one computer, I did:
Code:
ssh-keygen -t rsa

Then I copied the public key to the other computer:
Code:
ssh-copy-id -i ~/.ssh/id_rsa.pub remoteuser@remote_host

Now when I ssh from the local computer on a specific user account to the remote computer with a specific user account, it no longer prompts for a password for ssh.

Then I can just do stuff like this:
Code:
scp remoteuser@remote_host:/home/remoteuser/somesortof.log /home/localuser/somesortof.log

In this command line, I'm copying from the second computer to the first computer (where I created the pub/pvt key pair).

The nice thing here is no 3rd computer needed. And no passwords being passed or exposed.
# 5  
Old 09-23-2013
Quote:
Originally Posted by Corona688
You do realize that your password is visible to the entire system when you do this, yes?

ssh makes it a pain to pass around password because doing so is a really bad idea.
Sorry for the late reply!

Corona688: No, I don't type the password in the script, rather I request the user to type the password, read it as a variable and use that in the sshpass -p "$pwd"

DGPickett: I don't understand this, can you show an example?

//use the ssh cat twice to copy files through your host, or//

nbsparks: Thanks, I know about ssh-keygen, there's just too many servers for which I can't just go and do this!
# 6  
Old 09-23-2013
Quote:
Originally Posted by mathbalaji
Corona688: No, I don't type the password in the script, rather I request the user to type the password, read it as a variable and use that in the sshpass -p "$pwd"
...and it is visible to the entire system when you do so.

Why not just let ssh ask for its own password?

Last edited by Corona688; 09-23-2013 at 02:16 PM..
# 7  
Old 09-23-2013
Quote:
Originally Posted by Corona688
...and it is visible to the entire system when you do so.

Why not just let ssh ask for its own password?
Sorry if this is a stupid question, I'm a novice at this, but how is that visible to the entire system? I'm getting the password one time during the execution of the script. Here's a bit from my script:

Code:
read -s -p "Enter user1's server password: " pwd
sshpass -p "$pwd" user1@server1 somecmd
sshpass -p "$pwd" user1@server2 somecmd

The reason why I'm asking the user to enter the password is because I have multiple lines where I have to login into different servers (with same user, ofcourse), so I don't want the user to enter the password for multiple times.

Do you think reading the password using the above way will still be visible to the entire system?
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

How to pass password as a variable for sshpass authentication?

Using below below command i'm able to connect or authenticate server, In below command password contains special characters sshpass -v -p 'ASJBA%hs76)#' ssh -q -o ConnectTimeout=5 hostname But If I pass password as a variable I'm not able to connect or authenticate server, can you please help... (1 Reply)
Discussion started by: sam@sam
1 Replies

2. Shell Programming and Scripting

Put a command into router through sshpass bash script

hello, i am facing some issue. I am using a simple bash script that via sshpass put a command into router. Now, problem is that i have a file and commands into it. sshpass -p $pass ssh -o $log -n $user@$h /ip address set address=10.0.0.1/24 so if I have that command ip address set ... (0 Replies)
Discussion started by: tomislav91
0 Replies

3. Shell Programming and Scripting

Cannot sshpass router

Hi, I am trying to use sshpass to login to my router and then execute a reboot command. But the command never executes, can someone please help me. This doesnt work.... sshpass -p 'password' ssh 192.168.1.1 -l root -o StrictHostKeyChecking=no "sys reboot" However if I try following then it... (4 Replies)
Discussion started by: jeetz
4 Replies

4. Solaris

How to install SSHPASS on Solaris ???

Could you please let me know the steps: how to install sshpass command tool in solaris any version greater than 8. (2 Replies)
Discussion started by: lohith.dutta
2 Replies

5. Shell Programming and Scripting

problem with sshpass

Hello i am using sshpass to pass remote password into script but phase some problems when try to execute some commands remotely which means that the remote env not passed through sshpass for example sshpass -p 'XXX' ssh -o StrictHostKeyChecking=no -l myserver myserver visu_fis_pnes ... (2 Replies)
Discussion started by: mogabr
2 Replies

6. UNIX for Advanced & Expert Users

help with scp

hi all in my script i was using the "scp" command to copy 2 files from a certain directory on server A to the same directory on another server B, but for some reason its only copying the first file in the directory. This is the frst time that i used the scp command,any ideas appreciated. thnks (5 Replies)
Discussion started by: bkan77
5 Replies

7. UNIX for Advanced & Expert Users

Scp

I am trying to transfer a 10g files using scp, but I am getting timeout errors is there anywhere that I can modify a config file or something to increase the time. (4 Replies)
Discussion started by: rbizzell
4 Replies
Login or Register to Ask a Question