Script to ssh to a unix server?

I guest you want to remote connect your *nix server from network. Base on my guest, to: connect to remote *nix server, everybody are using SSH ssh anitha@anitha ip-to-unix-server automatic connect, write simple bash shell wrap around your ssh connect command and do something, not suggested, you should use ssh password less login (aka public/private key)! /usr/bin/env bash ip=172.16.0.1 #replace 172.16.0.1 with your unix server's ip username=anitha #your ssh username password=anitha #your ssh password command=who #what do you want to do with remote server arguments= #arguments for your command expect -c 'spawn ssh $username@$ip ; expect password ; send "$password\n" ; interact connect without typing password, you may need to use SSH password less login.

I guest you want to remote connect your *nix server from network. Base on my guest, to: connect to remote *nix server, everybody are using SSH ssh anitha@anitha ip-to-unix-server automatic connect, write simple bash shell wrap around your ssh connect command and do something, not suggested, you should use ssh password less login (aka public/private key) #! /usr/bin/env bash ip=172.16.0.1 #replace 172.16.0.1 with your unix server's ip username=anitha #your ssh username password=anitha #your ssh password command=who #what do you want to do with remote server arguments= #arguments for your command expect -c 'spawn ssh $username@$ip ; expect password ; send "$password\n" ; interact' connect without typing password, you may need to use SSH password less login.

1 ssh $username@$password $ip $command $arguments won't work (using standard openssh at least) - the password will be interpreted as a hostname, the ip as a command, and the command as the first argument. Passwordless login is the way to go. – Robin Green May 24 at 12:52 Thank you for your explain.

I have fixed. – olragon May 24 at 18:44.

Use sshpass if you really need to use non-interactive keyboard-interactive authentication (pun intended) or better switch to using pubkey-based authentication. Note that passing the password in clear to the ssh client is very lame as the password gets exposed in the publicly-readable process list where it can be read by anyone. Sshpass works around this problem by creating a pseudo-terminal and communicating with the ssh client using it, so at least the password is not exposed at runtime.

You should use expect, which is an extension of tcl that was made specifically for automating login tasks. Basic ssh login question: could not able to spawn(ssh) using expect How to interact with the server programattically after you have established the session: Expect Script to Send Different String Outputs.

No! Using passwords like that is significantly less secure than using RSA keys. Of course, once you've done that then you hardly need to use the complexity of expect unless you're automating something nasty on the remote end (which ls definitely isn't…) – Donal Fellows May 24 at 14:11 @Donal, remember that not everyone is a system administrator; automation is often required in lab environments where password security is not relevant.

Furthermore some devices (like those running Cisco IOS) cannot use RSA key authentication. This is a simple example meant to illustrate a concept. Add key authentication or whatever you like... then again, I know you are intimately familiar with Tcl, so "you" is whatever reader follows.

– Mike Pennington May 24 at 14:29 On most systems, adding an RSA key does not require any system privileges, just placing a public key in the right place (a one-time setup). Given that the result allows an admin to close off all password-based logins (so absolutely defending against distributed cracks) I'm surprised that so many still resist it. – Donal Fellows May 24 at 15:23 Cisco routers though… well, Cisco are a bunch of unhung scum in this respect; they charge a fortune for allowing you to log in securely, as its only supported on their high-end kit.

I could rant rather a lot on the topic, but I don't think that really belongs on SO. It's more of a thing for slashdot… – Donal Fellows May 24 at 15:24.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions