LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 01:08 PM   #1
jefsa
Member
 
Registered: Mar 2012
Posts: 83
Blog Entries: 1

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, 04:09 PM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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, 04:10 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 02: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 02:53 AM. Reason: pasted the wrong link ;0(
 
Old 03-20-2012, 09:43 AM   #5
jefsa
Member
 
Registered: Mar 2012
Posts: 83

Original Poster
Blog Entries: 1

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, 11:37 AM   #6
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 02:05 PM   #7
jefsa
Member
 
Registered: Mar 2012
Posts: 83

Original Poster
Blog Entries: 1

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, 02:28 PM   #8
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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, 02:53 PM   #9
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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, 03:09 PM   #10
jefsa
Member
 
Registered: Mar 2012
Posts: 83

Original Poster
Blog Entries: 1

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, 04:18 PM   #11
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
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, 05:02 PM   #12
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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 05:03 PM.
 
  


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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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