LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-01-2018, 12:16 PM   #1
harboa
LQ Newbie
 
Registered: Feb 2018
Posts: 14

Rep: Reputation: Disabled
How to use sFTP with Key-Pair and Password


Hi Guys,

Hope this is in the correct section! Sorry if not..

This one is driving me nuts! I've been trawling through the Forums in various places and I can't seem to find the answer..

All I want to do is set up a script to make an sFTP connection (ie. to run from CRON, no user interaction) to a customer using key-pair authentication and Password, download some files and then delete them from the remote location. The download and delete should be fairly easy but I'm struggling on the connection..

Everywhere seems to be saying use key_pair on it's own but this customer requires the password in addition to that (this is NOT a password on the key BTW..!). We don't have SSHPASS installed (and I'd like to avoid that if possible) and it is running on CentOS (as far as I am aware).

Any help would be greatly appreciated!

Thanks
 
Old 05-01-2018, 02:39 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,972

Rep: Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677
Quote:
it is running on CentOS
What do you mean by it, client or server?

sshpass or an expect script would be a couple of ways to automatically enter a ssh password.
 
Old 05-01-2018, 03:31 PM   #3
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,309

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
is sshfs a possibility ?
 
Old 05-01-2018, 08:39 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by harboa View Post
(ie. to run from CRON, no user interaction) to a customer using key-pair authentication and Password
Huh?
 
Old 05-01-2018, 09:24 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,972

Rep: Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677
I've not tried but I assume the OP's customer is using two factor authentication. Since version 6.2 you can use the AuthenticationMethods directive whereby you can require multiple methods. As the OP stated this is not the same thing as a passphrase. I am guessing this is how the server is configured.

AuthenticationMethods publickey,password

There is also RequiredAuthentications2 directive which is available in Redhat/CentOS in version 6 but not sure where else.

RequiredAuthentications2 publickey,password

Last edited by michaelk; 05-01-2018 at 09:26 PM.
 
1 members found this post helpful.
Old 05-02-2018, 03:17 AM   #6
harboa
LQ Newbie
 
Registered: Feb 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
What do you mean by it, client or server?

sshpass or an expect script would be a couple of ways to automatically enter a ssh password.
Sorry - a mistype there! Should have read "we are using CentOS".

So, we need to connect to their server which is running 2 factor authentication. I've not used an expect script before - how do they work?
 
Old 05-02-2018, 03:24 AM   #7
harboa
LQ Newbie
 
Registered: Feb 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Just read a bit more on "expect" - so, like SSHPASS, is something that would need to be installed.

Is there any way to accomplish this scripting without having to install anything more - ie. in native scripting (such as BASH)? I have limited access to the server I am using and installing new software would need to go through significant internal processes (and therefore delays)..
 
Old 05-02-2018, 03:26 AM   #8
harboa
LQ Newbie
 
Registered: Feb 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by schneidz View Post
is sshfs a possibility ?
Unfortunately, no
 
Old 05-02-2018, 04:07 AM   #9
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,082
Blog Entries: 3

Rep: Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665Reputation: 3665
Quote:
Originally Posted by harboa View Post
Is there any way to accomplish this scripting without having to install anything more - ie. in native scripting (such as BASH)? I have limited access to the server I am using and installing new software would need to go through significant internal processes (and therefore delays)..
Not really. The easy way in that regard is to have expect or sshpass do their thing.

https://github.com/openssh/openssh-portable

Perhaps you could write directly to the relevant tty but that's just a guess.
 
Old 05-02-2018, 05:17 AM   #10
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,972

Rep: Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677Reputation: 5677
Because ssh passwords are not entered using a standard tty it can not be done using plain bash as far as I know.
 
1 members found this post helpful.
Old 05-02-2018, 06:13 AM   #11
harboa
LQ Newbie
 
Registered: Feb 2018
Posts: 14

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by michaelk View Post
Because ssh passwords are not entered using a standard tty it can not be done using plain bash as far as I know.
OK. I suspected this was the case (due to the lack of stuff on the web about it) but thought I'd try anyway.

Thanks for the updates and suggestions though - I'll see if we can get something through on SSHPASS..

Cheers
 
Old 05-02-2018, 06:26 AM   #12
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,154

Rep: Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489
A client that allows the specification of both the password and the key might serve. I would try psftp from the putty-tools, or lftp.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Key-pair installed but am getting Password prompt RobInRockCity Linux - Newbie 4 02-28-2016 08:25 PM
[SOLVED] sftp asking for password authentication but my public key is passwordless slepthien Linux - Newbie 9 03-07-2014 09:49 AM
password less sftp connectivity using public key kashifchughtai Linux - Newbie 7 06-24-2013 09:49 PM
SFTP without password and without public/ private key iamakshay Programming 2 10-19-2009 05:35 PM
ssh Key pair whoes Red Squirrel Linux - Security 2 08-17-2008 09:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 12:08 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