LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-13-2014, 07:42 AM   #1
cli
Member
 
Registered: Apr 2013
Distribution: RedHat, Cent, Ubuntu
Posts: 80

Rep: Reputation: Disabled
expect command help


Hi All,
I need to check ssh login without entering the password, so I have created a shell script as below and added password also in that.
Code:
$ cat ssh-login.sh 
#!/bin/bash
SERVER="localhost"
USERNAME="penguin"
PASSWORD="Pa55w0rd"
ssh $USERNAME@$SERVER
expect "password:"
send "$PASSWORD"
But it is not logging in and asking for enter the password. So pls help how to acheive this.
 
Old 11-13-2014, 07:59 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,207

Rep: Reputation: 2676Reputation: 2676Reputation: 2676Reputation: 2676Reputation: 2676Reputation: 2676Reputation: 2676Reputation: 2676Reputation: 2676Reputation: 2676Reputation: 2676
that is a shell script, but you need to write an expect script. Just look at this: http://www.thegeekstuff.com/2010/10/expect-examples/
 
1 members found this post helpful.
Old 11-13-2014, 08:11 PM   #3
cli
Member
 
Registered: Apr 2013
Distribution: RedHat, Cent, Ubuntu
Posts: 80

Original Poster
Rep: Reputation: Disabled
Thanks pan64,
Instead additional expect script, is it not possible in the same bash script to integrate the expect related commands?
 
Old 11-13-2014, 08:25 PM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

sorry but I think you are taking the wrong approach to this problem. You should never, IMHO, be storing passwords in scripts and passing them to ssh like this. Whenever I see someone asking a question about using expect I see it as a big red flag that they are doing something wrong.

Anyway, I strongly suggest that you use public/private key (most likely RSA) authentication with one of the following two options:

1. Use a key protected by a passphrase and use ssh-agent so that you only need to enter the passphrase once per session.

2. Do not protect your key with a passphrase but restrict what can be done when authenticating with that key by specifying a "command=" clause in the authorized_keys file on the server.

Whether you choose option 1. or option 2. will depend on the details of what you are doing.

Evo2.
 
Old 11-23-2014, 09:22 AM   #5
cli
Member
 
Registered: Apr 2013
Distribution: RedHat, Cent, Ubuntu
Posts: 80

Original Poster
Rep: Reputation: Disabled
Sorry Guru, I am expecting what I needed. And as we wanted to use sftp for upload/download the files/folders we would like to store the password in a file. As public/private key doesn't work for the sftp user's as their home directory permission itself is read only.(May be root user can solve this, but we never wanted to run behind root user.) So lftp solved my problem.

Last edited by cli; 11-24-2014 at 07:41 PM.
 
Old 11-23-2014, 09:43 AM   #6
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,459

Rep: Reputation: 2053Reputation: 2053Reputation: 2053Reputation: 2053Reputation: 2053Reputation: 2053Reputation: 2053Reputation: 2053Reputation: 2053Reputation: 2053Reputation: 2053
Quote:
Originally Posted by evo2 View Post
Hi,

sorry but I think you are taking the wrong approach to this problem. You should never, IMHO, be storing passwords in scripts and passing them to ssh like this. Whenever I see someone asking a question about using expect I see it as a big red flag that they are doing something wrong.
Never say never. While 99% of the time it is a bad idea, there are exceptions to every rule. I have one such script on my system, in a case where having a plain-text password in the script for the entire world to see is not an issue in the least, and setting up ssh keys would not be realistic.

Without knowing the OP's situation, it's impossible to say if this is the wrong approach.
 
1 members found this post helpful.
Old 11-24-2014, 03:22 PM   #7
jefro
Moderator
 
Registered: Mar 2008
Posts: 16,366

Rep: Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379
I like to use autoexpect for making expect scripts.

If you don't want to save ssh password then you might move up to a self signed certificate.
 
Old 11-24-2014, 07:59 PM   #8
cli
Member
 
Registered: Apr 2013
Distribution: RedHat, Cent, Ubuntu
Posts: 80

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jefro View Post
I like to use autoexpect for making expect scripts.

If you don't want to save ssh password then you might move up to a self signed certificate.
Sorry Guru, I didn't explain our requirements, so it may be difficult to you all in understanding what I wanted. Our requirement is to upload files/dirs into two locations at one shot. Those uploded files/folders will be automatically deleted after some particular days/weeks from our main ftp server but the same data will be exist forever in our local ftp server. We don't want public/private key method because first of all the sftp users home directory itself will be ready only, so the normal sftp users may not be able to set password less logins, so instead we wanted to store all variables in that script file itself like username, password file/dir path(s) which needs to be uploaded on the servers, then whoever wanted to upload they can use this script by just changing the username, password and file/dirs variables.
So I could made a small script using lftp over sftp and working nicely.

Last edited by cli; 11-24-2014 at 08:15 PM.
 
Old 11-24-2014, 09:41 PM   #9
jefro
Moderator
 
Registered: Mar 2008
Posts: 16,366

Rep: Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379Reputation: 2379
Thank you for the update. Sorry we didn't fully understand your issue.
 
  


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
[root@fugo trace]# sh expect.sh expect.sh: line 9: expect: command not found sivaloga Linux - Kernel 1 08-22-2013 04:29 AM
Expect command with PGP. rivacom Linux - General 4 08-17-2010 09:50 AM
[SOLVED] Execute a command using expect visu_kvg Linux - Newbie 4 08-05-2009 10:08 AM
How to use expect command? jprathap Linux - Newbie 1 11-21-2008 10:30 PM
How to use EXPECT command to scp or ssh? thefountainhead100 Linux - Software 6 03-28-2008 06:41 PM


All times are GMT -5. The time now is 06:12 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration