Entering password in script for ftp/sftp and telnet/ssh ?

All those commands that we don't really use very often, but that we should ! Documented or not, they worth it !
Post Reply
fdurante

Entering password in script for ftp/sftp and telnet/ssh ?

Post by fdurante »

I would to add in my bash script ftp/sftp and telnet/ssh commands to transfer files from 1 OXE to a remote OXE automatically, and everytime I have to enter password manually !

I ask my colleague about this problem and he told me to use "expect" but the module for this is not installed on OXE R7.1 (F5.401.27 Alcatel patch ). Do you have another solution ?
Is it possible to install the module for "expect" on Linux of OXE CS ?
And, then, how can I use expect for my password problem ?

Thank you in advance for your response !
krzysioD

Re: Entering password in script for ftp/sftp and telnet/ssh ?

Post by krzysioD »

I ask my colleague about this problem and he told me to use "expect" but the module for this is not installed on OXE R7.1 (F5.401.27 Alcatel patch ).
Very good colleague. Much knowleage. Expect for OXE (as lftp, zmodem, minicom, midnight commander, etc could be found and installed, just search for my posts about Mandrake 7.2 and archive ftp site. I think that i've olso put an Expect tool on this forum).
Do you have another solution ?
For example good unix book and redirection.
note:

Code: Select all

#cat << EOF | ftp -r 3 -P 65521 -a -v  ftp://mtcl:xyz1@191.254.1.2
#asc
#put import.txt
#EOF
I've said:
- 3 times Retry
- use Port 65521
- be Verbose
- use ASCii mode for txt files
- send file named import.txt

Just an example (OXE R8.0.1 to Windows server, should work on OXE from R5 to R9).
Gedeon

Re: Entering password in script for ftp/sftp and telnet/ssh ?

Post by Gedeon »

for ftp, you can use .netrc in login directory (see google for more explanations).
for ssh, you can use -l for specifie login, but for password I have no solution except expect or ssh key
for scp, you can specifie URL like scp MyFile user:password@hostname:/My/Path/to/the/file

G.
krzysioD

Re: Entering password in script for ftp/sftp and telnet/ssh ?

Post by krzysioD »

Well, you could use .rhost / /etc/host.equiv
if you really know what you are doing 8)
fdurante

Re: Entering password in script for ftp/sftp and telnet/ssh ?

Post by fdurante »

Thank you for your responses !

I need to use for my script :
ssh -> you told me that there is no solution except expect or ssh key. I think you talk about rsa keys public. What's the procedure to use this ? What kind of lines can I insert in my script to use this solution ?
telnet -> how can I enter the password in my script automatically ? Do I have to use expect too ?
sftp -> you told me with scp MyFile user:password@hostname:/My/Path/to/the/file, it's working -> I will check
ftp -> you told me that .netrc in login directory is OK. Is there another solution with a simple line as sftp (scp)

krzysioD, I don't find Expect tool on the forum. Do you have a link to download package which includes "expect" ?

Thank you in advance for your responses !
krzysioD

Re: Entering password in script for ftp/sftp and telnet/ssh ?

Post by krzysioD »

fdurante wrote:Thank you for your responses !

I need to use for my script :
ssh -> you told me that there is no solution except expect or ssh key. I think you talk about rsa keys public. What's the procedure to use this ? What kind of lines can I insert in my script to use this solution ?
Explanation could be found in every good google-like page, see (example)
1) http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc. ... ode31.html
2) http://www.cs.toronto.edu/~murray/compn ... s_ssh.html
3) http://www.debian-administration.org/articles/152
Just 1st page of google for "ssh passwordless login".
Note: on omnipcx OXE you got SSH version 1 (implemented by very popular openssh implementation).
In many modern unixes you have version 2nd. (So remember this while reading above texts).

fdurante wrote: telnet -> how can I enter the password in my script automatically ? Do I have to use expect too ?
Without en expect i don't see how. But well... i've shown you how to use FTP, without expect, use the force luke!
fdurante wrote: sftp -> you told me with scp MyFile user:password@hostname:/My/Path/to/the/file, it's working -> I will check
ftp -> you told me that .netrc in login directory is OK. Is there another solution with a simple line as sftp (scp)
If you got SSH don't use Telnet. Same with SFTP.
BTW: if you use ssh login based on keys, well you don't need to enter scp passwords...
S is for Secure, So Secure Shell, Secure FTP.
fdurante wrote: krzysioD, I don't find Expect tool on the forum. Do you have a link to download package which includes "expect" ?
Thank you in advance for your responses !
Search Mandrake 7.2 with TCL/TK packages. (rpm files). Just don't have time to track down very FTP sites with very old linux releases. Huh, my favorite one (SunSite) does not have this old stuff, will go for some old CD magazines when i got some spare time.

Anyone interested in hosting FTP server with old Mandrake? (basesystem for OXE R5-R9)
pilotrus

Re: Entering password in script for ftp/sftp and telnet/ssh ?

Post by pilotrus »

We use rlogin via mtcl account on OXE.
It is in standard tool of OXE. It is used in pcscopy.
krzysioD

Re: Entering password in script for ftp/sftp and telnet/ssh ?

Post by krzysioD »

r* tools like rlogin, rsh, rcp etc... are dead for me as they don't crypt.
Also level of auth is IP-only, if someone has any ip-knowleage and access to swith, you are sitting duck waiting for a shot.

Image
pilotrus

Re: Entering password in script for ftp/sftp and telnet/ssh ?

Post by pilotrus »

There are more other methods to keep security.
And approach to security problem have to be more complex.
fedoseevka_DUP

Re: Entering password in script for ftp/sftp and telnet/ssh ?

Post by fedoseevka_DUP »

SecureCRT scripts

#$language = "VBScript"
#$interface = "1.0"

Sub main
' turn on synchronous mode so we don't miss any data
crt.Screen.Synchronous = True

' Wait for a string that looks like "login: " or "Login: "
' Occasionally, a host needs to be kicked to display a
' login prompt.
If (Not crt.Screen.WaitForString("ogin: ", 5)) Then
crt.Screen.Send vbCr
crt.Screen.WaitForString "ogin: "
End If

' Send your username followed by a carriage return
crt.Screen.Send "mylogin" & VbCr

' Wait for a tring that looks like "password: " or "Password: "
crt.Screen.WaitForString "assword:"

' Send your password followed by a carriage return
crt.Screen.Send "mypassword" & VbCr

' turn off synchronous mode for normal input processing
crt.Screen.Synchronous = False
End Sub





#$language = "VBScript"
#$interface = "1.0"

Sub main
Dim passwd

' turn on synchronous mode so we don't miss any data
crt.Screen.Synchronous = True

' Wait for a string that looks like "login: " or "Login: "
crt.Screen.WaitForString "ogin: "

' Send your username followed by a carriage return
crt.Screen.Send "mylogin" & VbCr

' Wait for a tring that looks like "password: " or "Password: "
crt.Screen.WaitForString "assword:"

' prompt the user for a password
passwd = crt.Dialog.Prompt("Please enter your password:", "Enter Password", "", True)

' send the password and a carriage return
crt.Screen.Send passwd & VbCr

' turn off synchronous mode to restore normal input processing
crt.Screen.Synchronous = False
End Sub





#$language = "VBScript"
#$interface = "1.0"

Sub main
' turn on synchronous mode so we don't miss any data
crt.Screen.Synchronous = True

' Wait for a string that looks like "login: " or "Login: "
crt.Screen.WaitForString "ogin: "

' Send your username followed by a carriage return
crt.Screen.Send "mylogin" & VbCr

' Wait for a tring that looks like "password: " or "Password: "
crt.Screen.WaitForString "assword:"

' Send your password followed by a carriage return
crt.Screen.Send "mypassword" & VbCr

' turn off synchronous mode to restore normal input processing
crt.Screen.Synchronous = False
End Sub
Post Reply

Return to “Usefull commands”