LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 07-04-2003, 04:16 AM   #1
DenZ
LQ Newbie
 
Registered: Jul 2003
Location: Paris
Distribution: debian
Posts: 3

Rep: Reputation: 0
Unhappy Ssh shell Programming


Hi,

I need a script shell to connect to a machine via ssh with password or pass phrase...

My problem is to not enter a pasword, I mean I don't want give password through keyboard . I want to pass it with an argument.

Please Help me

Thx
 
Old 07-04-2003, 04:43 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
you can connect without a password using DSA authorisation keys instead, but there is no way to store a pssword or anything like that, as it is not secure, so not possible. trying to pipe data to ssh.. e.g:

echo password | ssh user@host.com

will make ssh deliberatly fail. see openssh.com for info on setting up auth keys
 
Old 07-04-2003, 05:08 AM   #3
DenZ
LQ Newbie
 
Registered: Jul 2003
Location: Paris
Distribution: debian
Posts: 3

Original Poster
Rep: Reputation: 0
Of course I've tryed with echo ... | ssh ...
and it failed :-(
 
Old 07-07-2003, 05:08 AM   #4
DenZ
LQ Newbie
 
Registered: Jul 2003
Location: Paris
Distribution: debian
Posts: 3

Original Poster
Rep: Reputation: 0
Ok, if someone needs a solution you can try this (with expect )

#!/usr/bin/expect -f

set ip [lindex $argv 0]
set login [lindex $argv 1]
set password [lindex $argv 2]
set cmd [lindex $argv 3]

set timeout -1

spawn $env(SHELL)
match_max 100000
send -- "ssh $login@$ip\r"

expect {
"connecting (yes/no)?" {send -- "yes\r"}
"assword:" {send -- "$password\r"}
}
expect {
"assword:" {send -- "$password\r"}
">" {}
}
expect ">"
send -- "$cmd\r"
expect ">"
send -- "exit\r"
expect "closed"
send -- "exit\r"
expect eof


Then you just need to call the script like this (of course you need expect command)
./script user@10.10.10.10 ls
or
./script user@10.10.10.10 "ls;cd..;ls" for multiple commands
 
Old 07-08-2003, 02:30 PM   #5
nxny
Member
 
Registered: May 2002
Location: AK - The last frontier.
Distribution: Red Hat 8.0, Slackware 8.1, Knoppix 3.7, Lunar 1.3, Sorcerer
Posts: 771

Rep: Reputation: 30
Maybe you should try using ssh-agent instead of this convoluted (if I may say so ) but imaginative method.

The following chunk of code that would be run at logon, and the agent ENV variables exported to every child shell. The ssh-add statement prompts for the passphrase and stores the unencrypted private RSA/DSA key for future use by client programs that request it. Only if the login-shell was created in any other way but by sshd ( the box runs an ssh server as well ), I dont want to start the freakin agent everytime I remote in.

Part of ~/.bash_profile
Code:
# Run SSH agent: if a login shell (implied) is created NOT via sshd
ps -ax | grep $PPID | grep sshd > /dev/null
if [ $? -eq 1 ] && [ -z "$SSH_AGENT_PID" ]
then
    eval $(/usr/bin/ssh-agent) > /dev/null 2> /dev/null
    /usr/bin/ssh-add
fi
And here's the snippet that kills it in ~/.bash_logout
Code:
# Kill the ssh-agent on logout
if [ -n "$SSH_AGENT_PID" ] && [ $SHLVL -eq 1 ]
then
        eval $(/usr/bin/ssh-agent -k);
fi
clear
With this setup, everytime you start the ssh client programs (ssh, scp, sftp ) from the above-said login shell or a child shell or a shell within an X terminal they check to see if the agent is running and gets the unencrypted private keys from it. Thus, neither the unencrypted keys nor the passphrase are stored in disk ( they are stored in memory and will be cleaned up when the ssh-agent dies) ; hence this is considered a secure alternative to providing the password everytime.

HTH

Last edited by nxny; 07-09-2003 at 03:32 AM.
 
  


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
shell programming qerf Linux - Newbie 9 11-12-2005 05:27 PM
shell programming qerf Linux - Newbie 5 11-06-2005 05:28 PM
programming shell tuls Slackware 3 08-24-2005 05:58 PM
Shell Programming aman_goel Linux - General 1 11-25-2004 08:50 PM
shell programming athenerx Programming 1 10-28-2001 04:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 01:33 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
Open Source Consulting | Domain Registration