LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 05-06-2019, 07:08 AM   #1
jbirdflyo
LQ Newbie
 
Registered: May 2019
Posts: 4

Rep: Reputation: Disabled
sFTP forcing to go interactive when non-interactive mode is desired.


Hi,
I've been using an automated script with our trading partner for at least 5 years without any issues. The TP recently updated their site (changed their protocol from DNS to HTTPS) and now I cannot run my scripts without getting sFTP "usage" error.

The command I'm using is
sftp id@hostinformation.com <<eoftp >${LOGDIR}/${SFTPMSG} 2>${LOGDIR}/${SFTPERR}
cd ${SFTPDIR}
get ${FILE}
bye
eoftp

I can manually access without any issues but the script wouldn't run.
All the logs I have are coming empty except the one that contains the usage error.
Any help would be greatly appreciated.
Thank you.
 
Old 05-06-2019, 08:40 AM   #2
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
It isn't clear why you're talking about DNS vs HTTPS - they are 2 completely different things and the latter wouldn't be used for lookups where the former would for sftp.

Your script suggests you were using default port 22 and had an ssh trust established with the TP.

When it works manually now are you having to input a password?

Did the TP whitelist your outbound IP on their new server?

Did the TP import your ssh key into the user, id, on their new server?

When I checked the only port I see open on hostinformation.com is 80 which is http NOT https. Port 22 (ssh/sftp) will not allow connection nor will port 443 (https). However, it may be I can't connect due to lack of whitelist at the TP for the address I came from. They don't need to whitelist my IP but they do need to whitelist yours.

If in fact they have moved from sftp (not DNS) to https you'd have to modify your script to do something like wget or curl. However, it would be extremely unusual for them to try to force B2B file transfers over https instead of something like ftp, ftps or sftp.
 
Old 05-06-2019, 08:50 AM   #3
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,378
Blog Entries: 3

Rep: Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772
You can do that with SFTP in batch mode, that would be the -b option. The prerequisite for that is key-based authentication.
 
Old 05-06-2019, 08:52 AM   #4
jbirdflyo
LQ Newbie
 
Registered: May 2019
Posts: 4

Original Poster
Rep: Reputation: Disabled
Sorry, I just had to put something in there as far as the host address goes.
Since I'm connecting to one of the major banks, I couldn't really show you the hostname, etc.
The port we are using is 22 for sure (I've confirmed this.)

So, here is a back story.
The bank and we had .ssh non-interactive connection previously. I was able to run my script and retrieve files as well as send them files.
However, they are planning on updating to this new site where I can only interactively connect and carry out the commands while non-interactive scripts are failing.
When I asked the bank about the changes and directory permission levels, the only answer I heard from them is "those two sites sit in the same Linux server and all set up has been migrated over. so, we don't need to exchange any ssh except, I had to accept a new host key for the site."

It's really confusing that I can type in commands and fetch the files without any issues but the script with the exact same commands will fail...
Do you think I will have to use "curl" or some other commands with the existing script commands?




Quote:
Originally Posted by MensaWater View Post
It isn't clear why you're talking about DNS vs HTTPS - they are 2 completely different things and the latter wouldn't be used for lookups where the former would for sftp.

Your script suggests you were using default port 22 and had an ssh trust established with the TP.

When it works manually now are you having to input a password?

Did the TP whitelist your outbound IP on their new server?

Did the TP import your ssh key into the user, id, on their new server?

When I checked the only port I see open on hostinformation.com is 80 which is http NOT https. Port 22 (ssh/sftp) will not allow connection nor will port 443 (https). However, it may be I can't connect due to lack of whitelist at the TP for the address I came from. They don't need to whitelist my IP but they do need to whitelist yours.

If in fact they have moved from sftp (not DNS) to https you'd have to modify your script to do something like wget or curl. However, it would be extremely unusual for them to try to force B2B file transfers over https instead of something like ftp, ftps or sftp.
 
Old 05-06-2019, 10:43 AM   #5
MensaWater
LQ Guru
 
Registered: May 2005
Location: Atlanta Georgia USA
Distribution: Redhat (RHEL), CentOS, Fedora, CoreOS, Debian, FreeBSD, HP-UX, Solaris, SCO
Posts: 7,831
Blog Entries: 15

Rep: Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669Reputation: 1669
Quote:
I can only interactively connect and carry out the commands
When you connect "interactively" is it giving you a password prompt?

Are you able to login because you know the password when doing it "interactively"?

If not prompting for password are you seeing any other prompts (e.g. is it asking you to accept new key/fingerprint from the remote)? if so what are the prompts and what are your responses?

When you do it "interactively" are you doing it from the same source USER and SERVER that your script runs as?

The way ssh/sftp work is based on the keys and fingerprints of same for the users involved. To enable a "trusted" connection (i.e. one that works without a password) you have to send the partner a public key (e.g. rsa or dsa) from the user on your side. The user on your side would also have the private key but you don't send that to the partner.
The partner stores the public key in the setup of whatever user on their side you're attempting. When the user on your side attempts the connection it identifies itself to the partner and on verifying it is the user they imported the key for they allow the connection.

It is important that you provide enough detail for people to help you with this.

We've had many partners (including banks) make changes and they almost always provide a document regarding what is changing.

If they've changed the user on their side they'd need to import your key into that new user's setup.

If they've changed the physical server you're attaching to, even if it has the same internet address and user they would need to import the key on the new server into the user.

If they've changed the protocol (e.g. from sftp to ftps) you'd have to work with the new protocol. Although sftp and ftps sound similar, they're completely different. ftps uses SSL certificates rather than keys. Some partners offer both and you should insist on sftp if they do. You can do ftps but would have to research how to do it.
 
Old 05-06-2019, 01:13 PM   #6
jbirdflyo
LQ Newbie
 
Registered: May 2019
Posts: 4

Original Poster
Rep: Reputation: Disabled
No Prompts what so ever...
I think I solved this problem.
With the new site, I had to add a space between sftp command and cd command.
like:
sftp id@hostinformation.com <<eoftp >${LOGDIR}/${SFTPMSG} 2>${LOGDIR}/${SFTPERR}

cd ${SFTPDIR}
get ${FILE}
bye
eoftp

It seems like having that blank space basically worked as an "enter key" to clear it out to the next command line.
Not sure how and why... never had to do this before... but it still works.






Quote:
Originally Posted by MensaWater View Post
When you connect "interactively" is it giving you a password prompt?

Are you able to login because you know the password when doing it "interactively"?

If not prompting for password are you seeing any other prompts (e.g. is it asking you to accept new key/fingerprint from the remote)? if so what are the prompts and what are your responses?

When you do it "interactively" are you doing it from the same source USER and SERVER that your script runs as?

The way ssh/sftp work is based on the keys and fingerprints of same for the users involved. To enable a "trusted" connection (i.e. one that works without a password) you have to send the partner a public key (e.g. rsa or dsa) from the user on your side. The user on your side would also have the private key but you don't send that to the partner.
The partner stores the public key in the setup of whatever user on their side you're attempting. When the user on your side attempts the connection it identifies itself to the partner and on verifying it is the user they imported the key for they allow the connection.

It is important that you provide enough detail for people to help you with this.

We've had many partners (including banks) make changes and they almost always provide a document regarding what is changing.

If they've changed the user on their side they'd need to import your key into that new user's setup.

If they've changed the physical server you're attaching to, even if it has the same internet address and user they would need to import the key on the new server into the user.

If they've changed the protocol (e.g. from sftp to ftps) you'd have to work with the new protocol. Although sftp and ftps sound similar, they're completely different. ftps uses SSL certificates rather than keys. Some partners offer both and you should insist on sftp if they do. You can do ftps but would have to research how to do it.
 
1 members found this post helpful.
Old 05-06-2019, 01:23 PM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,378
Blog Entries: 3

Rep: Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772
What about using the batch mode with keys, as mentioned in #3 above?

From "man sftp"

Quote:

-b batchfile
Batch mode reads a series of commands from an input batchfile
instead of stdin. Since it lacks user interaction it should be
used in conjunction with non-interactive authentication. A
batchfile of ‘-’ may be used to indicate standard input. sftp
will abort if any of the following commands fail: get, put,
reget, reput, rename, ln, rm, mkdir, chdir, ls, lchdir, chmod,
chown, chgrp, lpwd, df, symlink, and lmkdir. Termination on
error can be suppressed on a command by command basis by prefix‐
ing the command with a ‘-’ character (for example, -rm
/tmp/blah*).
 
Old 05-06-2019, 01:26 PM   #8
jbirdflyo
LQ Newbie
 
Registered: May 2019
Posts: 4

Original Poster
Rep: Reputation: Disabled
batch mode worked.
I had an unnecessary line at the very top of my batch file and that's how I figured out needing the space in between sftp command and cd command.
Thanks again for your help!

Quote:
Originally Posted by Turbocapitalist View Post
What about using the batch mode with keys, as mentioned in #3 above?

From "man sftp"
 
1 members found this post helpful.
Old 05-06-2019, 01:45 PM   #9
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,378
Blog Entries: 3

Rep: Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772Reputation: 3772
Ok but I did not see the -b in your examples.
 
  


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
[SOLVED] Of interactive and non-interactive shells. stf92 Linux - Newbie 1 10-05-2011 12:37 PM
Interactive and non-interactive shells? Tim356 Linux - Newbie 7 11-05-2008 10:32 PM
BASH - How to open an interactive script from a non interactive script..... OldGaf Programming 4 06-29-2008 04:34 PM
forcing traffic through certain route(forcing source ip) taltman Linux - Networking 1 12-26-2007 01:07 PM
interactive and non-interactive shell linuxjamil Programming 3 09-03-2006 08:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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