LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices

Reply
 
Search this Thread
Old 01-27-2008, 12:26 AM   #1
ikinnu
Member
 
Registered: Jun 2007
Posts: 64

Rep: Reputation: 15
ssh password from a text file


Hi,

I am writing a BASH script which should ssh to a server.
Is there any way such that ssh takes password from a text file so that
my script runs without any human interaction.

Thanks a lot in advance.
 
Old 01-27-2008, 12:45 AM   #2
overpencil
Member
 
Registered: Dec 2007
Posts: 32

Rep: Reputation: 15
this would be very bad practice.

If you want this setup, I would suggest instead using an ssh key without a password. This is also the normal ( accepted/more secure ) way of doing it.
 
Old 01-27-2008, 02:08 AM   #3
jantman
Member
 
Registered: Nov 2005
Location: New Jersey, USA
Distribution: SuSE
Posts: 492

Rep: Reputation: 31
SSH key is *definitely* the way to go.

This is extremely bad practice, but if you wanted to automate entry of information in an interactive environment, you'd want to use Expect.
 
Old 01-27-2008, 08:09 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,118
Blog Entries: 54

Rep: Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787Reputation: 2787
Quote:
Originally Posted by overpencil View Post
this would be very bad practice.

If you want this setup, I would suggest instead using an ssh key without a password. This is also the normal ( accepted/more secure ) way of doing it.
Agreed. If you go that route make sure you up your logging and restrict access to that account and what tasks that account may perform as much as possible.
 
Old 01-28-2008, 12:37 AM   #5
ikinnu
Member
 
Registered: Jun 2007
Posts: 64

Original Poster
Rep: Reputation: 15
I want to do it without using authorized_keys file. I should be able to ssh to any server using this script where my account exists. I am writing this script to run only in my home network where all of our friends work together on linux for expermentation purpose. Just want to save time typing passwords and without using authorized_keys :-)
 
Old 01-30-2008, 06:22 PM   #6
lujan
Member
 
Registered: Sep 2003
Distribution: Ubuntu, Debian Sarge, Mac OS X, FreeBSD
Posts: 45

Rep: Reputation: 16
Why don't you want to use authorized_keys? You are just going to be reinventing the wheel otherwise.
 
Old 02-13-2008, 11:36 PM   #7
ikinnu
Member
 
Registered: Jun 2007
Posts: 64

Original Poster
Rep: Reputation: 15
I am not expected to use this file in my office. Is there anyway the BASH can simulate the entering of password when ssh prompts for a password?

I mean to ask, Can i write a script such that I can detect some program waiting (ssh prompting for input in this case) and simulate the key strokes and an 'Enter' at the end :-) Is such a script possible to write?
 
Old 02-14-2008, 12:36 AM   #8
billymayday
Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
You could have set up the keys by now
 
Old 02-14-2008, 12:44 AM   #9
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
The general answer to your question is to use "expect". Keys are a better way to go.

Also look at the "ssh-agent" program. Using it you will only have to enter your passphrase once. Using authorized-keys with passphrases and agent is the most secure method according to the ssh manpages.
 
Old 02-14-2008, 01:57 AM   #10
Micro420
Senior Member
 
Registered: Aug 2003
Location: Berkeley, CA
Distribution: Mac OS X Leopard 10.6.2, Windows 2003 Server/Vista/7/XP/2000/NT/98, Ubuntux64, CentOS4.8/5.4
Posts: 2,986

Rep: Reputation: 45
Quote:
Originally Posted by billymayday View Post
You could have set up the keys by now
LOLLLLLLLLLLLL
 
Old 02-21-2008, 03:09 AM   #11
ikinnu
Member
 
Registered: Jun 2007
Posts: 64

Original Poster
Rep: Reputation: 15
Thanks a lot to all. I joined only recently here. Otherwise i would have put all keys long before

Yes i'll surely try the ssh-agent
 
Old 02-16-2011, 11:49 AM   #12
jdlacruz
LQ Newbie
 
Registered: Feb 2011
Location: Switzerland & Silicon Valley, USA
Distribution: Ubuntu, CentOS
Posts: 2

Rep: Reputation: 0
What about sshpass ?

Here I show a simple example:
sshpass -f user.pwd ssh user@hostserver path/command

Where -f indicates that the file contains the password (in this case: user.pwd)

The user@hostserver is the standard item

And the command, if you need to execute one, should be put at the end.

You can find more information here:
SSHPASS Tutorial
 
  


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
Steps needed to convert multiple text files into one master text file jamtech Programming 5 10-07-2007 11:24 PM
in Pascal: how to exec a program, discard text output or send to text file Valkyrie_of_valhalla Programming 6 05-02-2007 09:50 AM
how to change some text of a certain line of a text file with bash and *nix scripting alred Programming 6 07-10-2006 11:55 AM
Which light text editor can copy text from file and paste in browser? davidas Linux - Software 9 03-06-2006 11:28 AM
How to find and change a specific text in a text file by using shell script Bassam Programming 1 07-18-2005 07:15 PM


All times are GMT -5. The time now is 09:05 PM.

Main Menu
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