Results 1 to 6 of 6
Afternoon all,
Any help you can provide would be greatly appreciated.
NOTE : I am on a mac (Tiger 10.4 i.e. built on Unix) but I have a program that ...
- 01-11-2008 #1Just Joined!
- Join Date
- Jan 2008
- Posts
- 2
Shell script to log in to SSH server
Afternoon all,
Any help you can provide would be greatly appreciated.
NOTE : I am on a mac (Tiger 10.4 i.e. built on Unix) but I have a program that allows me to install any linux program. I think my issue is that I may be missing some, hence you may be able to point out the obvious.
i'm trying to write a shell script to automate the process of logging
in to a secure server.
Via Google I found :
SSH - Passing Unix login passwords through shell scripts - nixCraft Linux Forum
and
Ssh login expect script to supply password
and from that i've created :
ssh.login.exp
with the following result :Code:#!/usr/bin/expect -f # set Variables set username "username" set password "boo" set passwordroot "boo2" set ipaddr "192.168.1.1" set timeout -1 # now connect to remote UNIX box (ipaddr) with given script to execute spawn ssh $username@$ipaddr match_max 100000 # Look for passwod prompt expect "*?assword:*" # Send password aka $password send -- "$password\r" # send blank line (\r) to make sure we get back to gui send -- "\r" send -- "su\r" # Look for passwod prompt expect "*?assword:*" # Send password aka $password send -- "$passwordroot\r" expect eof
now, i've done as that first link instructed and installed the expectsCode:computer:~/Sites/shortcuts/wm fr33dom$ sh ssh.login.exp ssh.login.exp: line 24: spawn: command not found ssh.login.exp: line 25: match_max: command not found couldn't read file "*?assword:*": no such file or directory ssh.login.exp: line 29: send: command not found ssh.login.exp: line 31: send: command not found ssh.login.exp: line 32: send: command not found couldn't read file "*?assword:*": no such file or directory ssh.login.exp: line 36: send: command not found couldn't read file "eof": no such file or directory
module via a program called finkcommander:
Fink - Home
How to install Linux applications in OS X - a complete walkthrough - Simplehelp
yet, as you can see... no joy.
Am i missing some other linux programs maybe? or am i not calling the script correctly?
thanks again for your help,
fr33dom
- 01-11-2008 #2
- 01-15-2008 #3Just Joined!
- Join Date
- Jan 2008
- Posts
- 2
thank you
thanks mate, i had a look and found :
Howto Linux / UNIX setup SSH with DSA public key authentication (password less login)
Is this what you mean?
If so, I was also hoping to automate the second part that was to login as a root user. I'm not sure why I can't do this directly but it seems I cannot. Hence this workaround.
I can't figure out why my spawn command won't work from the .exp file, nor a .sh file. I have run "man spawn" and it exists so... What's the story?
As you can see, my knowledge of shell scripts is minute. Apologies.
Thanks again,
fr33dom
- 01-15-2008 #4
The walkthru you posted looks ok, except in step 2 I would set ~/.ssh directory permissions to 700 instead. Remember to use a blank passphrase, since this logon will be running from a script.
If you need to execute a command on the remote side (as root) you might look into making your user a sudoer for just that command and, again, not requiring a password to do it.
- 01-20-2008 #5Just Joined!
- Join Date
- Jan 2008
- Posts
- 1
Hi Experts,
The information provided here is really helpful but it does not serve my requirements.
I have more than 200 machines in my network running linux and I want to be able to ssh to each one of them using thier IP address stored in a file and then run some commands inside each machine, log out and log in the next machine in the list and do the same, so on ...
Now, using key-gen is not practical for me and I do not want to install the "expect" utility due to some reason.
Please tell me if there is any way to supply ssh password using bash scripting? I know supplying the password in script might not be very secure, but still I want to do it this way. I shall be greatful to any help.
Regards, R.
- 01-20-2008 #6


Reply With Quote