LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-09-2020, 10:21 AM   #1
dmchess
Member
 
Registered: Jan 2005
Posts: 244

Rep: Reputation: 43
scp and sshpass


I can get scp to send a file interactively where I get prompted for the server password.
If I try using sshpass in a bash script it fails. No error messages, it just doesn't show up.
Both machines are Linux Mint 19.2 running the Mate desktop.

This command works:

scp myfile.txt myuser@192.168.n.nnn:/home/myuser/Documents/mydir/

This command does not work

sshpass -p 'mypass' scp myfile.txt myuser@192.168.n.nnn:/home/myuser/Documents/mydir/

Both ssh and sshpass were downloaded from the repository. I installed openssh on both machines some time ago. I installed sshpass within the last few days on the sending machine only. Both machines are sitting on a home network
 
Old 07-09-2020, 10:40 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
Any reason you can't use keypair authentication instead of having to code a password into a script?
 
1 members found this post helpful.
Old 07-09-2020, 11:09 AM   #3
dmchess
Member
 
Registered: Jan 2005
Posts: 244

Original Poster
Rep: Reputation: 43
Have they taken this ability away from me. I did this a few years ago and it worked.
I do not need high security on my own private network. I just want a simple way to
move files between computers.
 
Old 07-09-2020, 11:27 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
sshpass works for me from both command line and a bash script running debian as the client. Just for a frame of reference does sshpass work if just using ssh?

sshpass -p 'mypass' ssh myuser@192.168.n.nnn

FYI posting the complete private IP address in no ways reveals any public or private information.

I prefer to use keys instead of sshpass.

The file manager has a built in sftp client and can save passwords so its possible to do the same thing from the GUI too.

Last edited by michaelk; 07-09-2020 at 11:38 AM.
 
Old 07-09-2020, 11:39 AM   #5
dmchess
Member
 
Registered: Jan 2005
Posts: 244

Original Poster
Rep: Reputation: 43
sshpass -p 'mypass' ssh myuser@192.168.n.nnn

Yes that works, but I don't know how that solves my problem.

Last edited by dmchess; 07-09-2020 at 11:46 AM.
 
Old 07-09-2020, 11:48 AM   #6
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
What happens if you run scp with sshpass from the command line?
 
Old 07-09-2020, 12:04 PM   #7
dmchess
Member
 
Registered: Jan 2005
Posts: 244

Original Poster
Rep: Reputation: 43
What happens if you run scp with sshpass from the command line?

That does work. Now why doesn't it run from a script?
 
Old 07-09-2020, 12:32 PM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
I don't know. Can you post the actual script?
 
Old 07-09-2020, 12:34 PM   #9
camorri
LQ 5k Club
 
Registered: Nov 2002
Location: Somewhere inside 9.9 million sq. km. Canada
Distribution: Slackware 15.0, current, slackware-arm-currnet
Posts: 6,215

Rep: Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849
Quote:
Now why doesn't it run from a script?
Post the script, and maybe we can help.
 
Old 07-09-2020, 03:40 PM   #10
dmchess
Member
 
Registered: Jan 2005
Posts: 244

Original Poster
Rep: Reputation: 43
#!/bin/bash
set -x
shpass -p 'MyPass' scp /home/terry/Documents/fpc/Test/MyFile.txt terry@192.168.0.100:/home/terry/Documents/fpc/Test/

# I also tried
# Cmd="shpass -p 'MyPass' scp /home/terry/Documents/fpc/Test/MyFile.txt terry@192.168.0.100:/home/terry/Documents/fpc/Test/"
# echo `$Cmd`
#Which also did not work

#This is a very simple script, I was going to execute it from a Pascal Program.
#I had also tried using Pascal's TProcess

#ScpProcess := TProcess.create(Nil);
#ScpProcess.Executable := 'sshpass';
#ScpProcess.Parameters.Add('-p');
#ScpProcess.Parameters.Add('''MyPass''');
#ScpProcess.Parameters.Add('scp');
#ScpProcess.Parameters.Add('ScpExample.pas');
#ScpProcess.Parameters.Add('terry@192.168.0.100:/home/terry/Documents/fpc/Test/');
#ScpProcess.Options := ScpProcess.Options + [poWaitOnExit];
#ScpProcess.Execute;
#Again, no errors, but the file was not copied.
#So I am kind of running out of ideas.

Last edited by dmchess; 07-09-2020 at 03:48 PM.
 
Old 07-09-2020, 04:28 PM   #11
camorri
LQ 5k Club
 
Registered: Nov 2002
Location: Somewhere inside 9.9 million sq. km. Canada
Distribution: Slackware 15.0, current, slackware-arm-currnet
Posts: 6,215

Rep: Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849
I got the first shell script to work.

Quote:
#!/bin/bash
set -x
shpass -p 'MyPass' scp /home/terry/Documents/fpc/Test/MyFile.txt terry@192.168.0.100:/home/terry/Documents/fpc/Test/
I copied the above line, modified shpass to sshpass, editited the password for my remote system, and edited the IP address to match my home network. I had to create a MyFile.txt as a test file. I also shortened the path to MyFile.txt on both ends. I gave the script a name of testcopy and made it executable. I ran the command sh testcopy, and got the following output.

Quote:
sh testcopy
+ sshpass -p xxxxxxx scp /home/cliff/Documents/MyFile.txt cliff@192.168.1.100:/home/cliff/Documents/MyFile.txt
Note, I x'ed out my password.

Hope this helps.

I don't know anything about Pascal, possibly someone else will chime in and help there.

Last edited by camorri; 07-09-2020 at 04:31 PM.
 
Old 07-09-2020, 05:30 PM   #12
dmchess
Member
 
Registered: Jan 2005
Posts: 244

Original Poster
Rep: Reputation: 43
I'm sorry, the documentation I saw said you had to have single quotes around the password.

Terry.
 
Old 07-09-2020, 06:16 PM   #13
camorri
LQ 5k Club
 
Registered: Nov 2002
Location: Somewhere inside 9.9 million sq. km. Canada
Distribution: Slackware 15.0, current, slackware-arm-currnet
Posts: 6,215

Rep: Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849Reputation: 849
FWIW, I tried it with and without single quotes, worked both ways.
 
Old 07-09-2020, 06:34 PM   #14
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
Same here, worked for me both ways.
 
Old 07-10-2020, 02:29 PM   #15
dmchess
Member
 
Registered: Jan 2005
Posts: 244

Original Poster
Rep: Reputation: 43
Btw, the Pascal worked once I removed the quotes from the string.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
redhat 8 and sshpass availability edwardsmarkf Red Hat 4 01-18-2020 05:36 PM
[SOLVED] scp using sshpass har_85 Programming 5 03-04-2014 05:38 AM
LXer: sshpass command : Non-interactive Password Authentication with SSH LXer Syndicated Linux News 0 08-27-2013 03:40 PM
sshpass issue in executing commands in sftp Mode. pradeepdee6 Linux - Newbie 7 04-17-2013 09:18 AM
LXer: sshpass - Non-interactive ssh password authentication LXer Syndicated Linux News 0 05-04-2008 04:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration