Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Sftp connection with password

Shell Programming and Scripting


Tags
sftp, shell

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 2 Weeks Ago   -   Original Discussion by himanshupant
himanshupant's Unix or Linux Image
himanshupant himanshupant is offline
Registered User
 
Join Date: Feb 2018
Last Activity: 12 April 2018, 7:53 AM EDT
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
Computer Sftp connection with password

I am running this script to copy pattern files in local but it is asking for password even passing the hardcode value

Script:-



Code:
PASSWORD="xyz"
sftp -oport=1002 user@host:/dir/archive/file*.txt  /di/data/
<< EOF
$PASSWORD
quit
EOF

Got error :-



Code:
-bash-4.1$ sh sftp_with_password.sh
Connecting to user@host...
Password Authentication


Please suggest on this.


Moderator's Comments:
Sftp connection with password Please use CODE tags as required by forum rules!

Last edited by rbatte1; 1 Week Ago at 12:26 PM.. Reason: RudiC Added CODE tags. rbatte1 took out auto-email formating
Sponsored Links
    #2  
Old Unix and Linux 2 Weeks Ago   -   Original Discussion by himanshupant
stomp's Unix or Linux Image
stomp stomp is offline
Registered User
 
Join Date: May 2016
Last Activity: 24 April 2018, 4:24 PM EDT
Posts: 213
Thanks: 10
Thanked 74 Times in 69 Posts
Embedding passswords in clear text in scripts is bad practise and ssh/sftp is designed to prohibit such usage.

The first approach to take is to generate an SSH-Key and deposit the public key part in target hosts $HOME/.ssh/authorized_keys file.



Code:
ssh-keygen
...
ssh-copy-id user@host

If that does not work, try to find the error why.
Sponsored Links
    #3  
Old Unix and Linux 2 Weeks Ago   -   Original Discussion by himanshupant
himanshupant's Unix or Linux Image
himanshupant himanshupant is offline
Registered User
 
Join Date: Feb 2018
Last Activity: 12 April 2018, 7:53 AM EDT
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
I don't have access to right SSH file. It is the only way to use hardcode
    #4  
Old Unix and Linux 2 Weeks Ago   -   Original Discussion by himanshupant
stomp's Unix or Linux Image
stomp stomp is offline
Registered User
 
Join Date: May 2016
Last Activity: 24 April 2018, 4:24 PM EDT
Posts: 213
Thanks: 10
Thanked 74 Times in 69 Posts
Did you really try to write the file with sftp?

---

In case there's really no way, you may use sshpass for that case....

The source is located here:

SourceForge - sshpass

Major Linux Linux distributions have that package included.
Sponsored Links
    #5  
Old Unix and Linux 2 Weeks Ago   -   Original Discussion by himanshupant
himanshupant's Unix or Linux Image
himanshupant himanshupant is offline
Registered User
 
Join Date: Feb 2018
Last Activity: 12 April 2018, 7:53 AM EDT
Posts: 7
Thanks: 3
Thanked 0 Times in 0 Posts
While using sshpass, it shows command not found
Do I need to install package and will it impact other job ?
Sponsored Links
    #6  
Old Unix and Linux 1 Week Ago   -   Original Discussion by himanshupant
rbatte1's Unix or Linux Image
rbatte1 rbatte1 is offline Forum Staff  
Root armed
 
Join Date: Jun 2007
Last Activity: 26 April 2018, 1:23 PM EDT
Location: Lancashire, UK
Posts: 3,515
Thanks: 1,546
Thanked 691 Times in 621 Posts
On the target server, can you use the credentials your have to sign in and look in the home directory for a .ssh directory? What permission do you have on that directory and particularly the authorized_keys file.


Robin
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
New sftp connection jegaraman Red Hat 1 12-23-2015 01:51 PM
SFTP prompting for password even though password is in script megha2525 Shell Programming and Scripting 6 01-29-2014 01:01 PM
For SFTP connection - How to give password in UNIX Script (ksh) Vineeta Nigam UNIX for Dummies Questions & Answers 4 12-04-2012 10:15 AM
Password less connection(sftp/ssh) panknil Shell Programming and Scripting 2 11-27-2009 11:04 AM
SFTP Connection Closed ed.browne UNIX for Advanced & Expert Users 1 07-23-2008 01:07 AM



All times are GMT -4. The time now is 08:49 PM.