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 03-14-2012, 02:08 PM   #1
jefsa
Member
 
Registered: Mar 2012
Posts: 33

Rep: Reputation: Disabled
ssh autologin using scripting under vi


Hi All,

Pretty new to Linux and I could use some help.

I am trying to write a script where I will be able to automaticaly access a Cisco 2950 switch and then later perform some functions. I have the switch setup manually using ssh with no problems.

The problem with the several attempts at this is I do not know how to enter the password in the script so it sees it after the switch prompts for it and enters it autmattically.

When I run the script this is what I want run in the background (I do not want to see any replies back on the terminal):
ssh -l rici cisco1 <command to login into switch>
rici@cisco1's password: <this is what comes back, and at this point I would manually enter the password. I would like to automate this step>.

I have looked all over the web for some guidance but do not understand most of what is being said. Just need a little help!

I am running Slackware using vi.

Thanks,

Regards,

Jeff
 
Old 03-14-2012, 05:09 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Can you store a SSH key on the switch? If so, that would be the simplest solution. Otherwise, consider trying the expect tool.

--- rod.
 
Old 03-14-2012, 05:10 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Hi, welcome to LQ!


I'm not sure I understand the relation between the cisco switch and vi in your
scenario; the common solution to automatic logins (if the device doesn't allow
for passwordless logins via ssh-keys) is to use expect. You can use any editor
to write an expect script, including vi.

https://www.google.com/search?q=linu...sh+login+cisco



Cheers,
Tink

P.S.: Too slow :D
 
Old 03-15-2012, 03:40 AM   #4
jonmcc
LQ Newbie
 
Registered: Dec 2005
Distribution: Fedora Core 4
Posts: 7
Blog Entries: 1

Rep: Reputation: 2
Basically, you need promptless access to the switch. Instructions here...

http://www.cisco.com/en/US/docs/ios/...html#wp1082784

Repost if you still having problems ;0)

Last edited by jonmcc; 03-15-2012 at 03:53 AM. Reason: pasted the wrong link ;0(
 
Old 03-20-2012, 10:43 AM   #5
jefsa
Member
 
Registered: Mar 2012
Posts: 33

Original Poster
Rep: Reputation: Disabled
Hi All,

This is what is happening since my first post. I have been trying to install expect5.45 which is the latest version. When I cd to expect5.45 and try to run ./configure I get the following message at the end:
"checking for Tcl private include files... configure: error: Cannot find private header tclInt.h in /tmp/tcl8.5.5". I have no clue on what this means but I am sure this is stoping the creation of the Makefile that is required for the installation process.

I really could use some help with this!

Thanks.

Regards,
Jeff
 
Old 03-20-2012, 12:37 PM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Silly question, but why don't you just use the expect that
already comes with Slackware? Does the version you're trying
to build from source give you features the current one doesn't?


Cheers,
Tink
 
Old 03-29-2012, 03:05 PM   #7
jefsa
Member
 
Registered: Mar 2012
Posts: 33

Original Poster
Rep: Reputation: Disabled
Hi All,

I finally after sometime got my script working using expect and yes Tinkster with the version that was installed already. Now my question concerning the script itself:

Is there a way to mask/hide the password that I have entered into the script after the "send" command?
Meaning, when I re-open the script I do not want to see the password that is required to access the Cisco switch.

Thanks.

Regards,

Jeff
 
Old 03-29-2012, 03:28 PM   #8
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 3,222

Rep: Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155
Quote:
Originally Posted by jefsa View Post
Is there a way to mask/hide the password that I have entered into the script after the "send" command?
Meaning, when I re-open the script I do not want to see the password that is required to access the Cisco switch.
I don't believe it's possible. Anything you code in your script to extract and decode some encrypted password stored somewhere, can be replicated by anybody who views your script. It would be no more secure than just writing the password in plain text. The easiest way would be to just restrict the permissions on your script so that only you can read it. Remove the read permission for all other users.

Another option is to store the password in plain text in a separate file and pull it into your script, then use something like gpg to encrypt that file. Whenever you need to run your script, decrypt the password file, run the script, then re-encrypt the password file when you're done.
 
1 members found this post helpful.
Old 03-29-2012, 03:53 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally Posted by jefsa View Post
Hi All,

I finally after sometime got my script working using expect and yes Tinkster with the version that was installed already. Now my question concerning the script itself:

Is there a way to mask/hide the password that I have entered into the script after the "send" command?
Meaning, when I re-open the script I do not want to see the password that is required to access the Cisco switch.

Thanks.

Regards,

Jeff
As suicidal said - that (hiding) is not possible.

I still don't see why you won't simply use password-less ssh connections; which
version of IOS is your switch running?



Cheers,
Tink
 
Old 03-29-2012, 04:09 PM   #10
jefsa
Member
 
Registered: Mar 2012
Posts: 33

Original Poster
Rep: Reputation: Disabled
Hi Tink,

Not clear on what password-less is. The only way I know how to access the switch is setting up keys and creating a password.

Cisco 2950
Version 12.1(22)EA9

Thanks.

Regards,

Jeff
 
Old 03-29-2012, 05:18 PM   #11
suicidaleggroll
Senior Member
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 3,222

Rep: Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155Reputation: 1155
Password-less login uses SSH keys without a passphrase, so when you ssh or scp to the remote machine, the remote machine compares your machine's key against its own list in its authorized_keys file, if it matches, it lets you in without prompting for a password or passphrase.
 
Old 03-29-2012, 06:02 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Quote:
Originally Posted by jefsa View Post
Hi Tink,

Not clear on what password-less is. The only way I know how to access the switch is setting up keys and creating a password.

Cisco 2950
Version 12.1(22)EA9

Thanks.

Regards,

Jeff
keys is the key, indeed. You'd set-up a passphrase. And once you have
ssh-agent going for your user-account, and have added yourself to it (ssh-add)
using the passphrase it will let you connect to the switch w/o having to enter
a password.



Cheers,
Tink

Last edited by Tinkster; 03-29-2012 at 06:03 PM.
 
  


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
sftp user with limited ssh permissions to autologin using publickey blazingrock4u Linux - Security 1 10-18-2010 12:52 PM
SSH autologin FreeBSD -> CentOS5 Ghostwheel Linux - General 6 03-25-2009 12:51 AM
SSH/SCP Autologin overpeer Linux - Security 8 10-19-2005 07:51 AM
Autologin to KDE from SSH skorpi0wn Linux - Software 1 04-19-2005 12:22 AM
SSH and autologin? presstone Linux - General 8 03-12-2003 09:40 PM


All times are GMT -5. The time now is 01:57 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration