How to use ssh command in shell script?

This cannot be done with a simple ssh command, for security reasons. If you want to use the password route with ssh, the following link shows some scripts to get around this, if you are insistent.

This cannot be done with a simple ssh command, for security reasons. If you want to use the password route with ssh, the following link shows some scripts to get around this, if you are insistent: Scripts to automate password entry.

The best way to do this is by generating a private/public key pair, and storing your public key on the remote server. This is a secure way to login w/o typing in a password each time. Read more here.

For those on windows, I recommend the "putty" set of tools. For this scenario, the pageant tool would handle key management. Pglombardo gives the overview of using public key auth on *nix.

I've set this up many times on linux, and it can be a challenge at times. If you have specific problems setting it up, post them here – RyanHennig Oct 15 '10 at 18:55.

The ssh command will prompt for your password. It is unsafe to specify passwords on the commandline, as the full command that is executed is typically world-visible (e.g. Ps aux) and also gets saved in plain text in your command history file. Any well written program (including ssh) will prompt for the password when necessary, and will disable teletype echoing so that it isn't visible on the terminal.

If you are attempting to execute ssh from cron or from the background, use ssh-agent.

The way I have done this in the past is just to set up a pair of authentication keys. That way, you can log in without ever having to specify a password and it works in shell scripts. There is a good tutorial here: linuxproblem.org/art_9.html.

SSH Keys are the standard/suggested solution. The keys must be setup for the user that the script will run as. For that script user, see if you have any keys setup in ~/.

Ssh/ (Key files will end with a . Pub extension) If you don't have any keys setup you can run: ssh-keygen -t rsa which will generate ~/. Ssh/id_rsa.

Pub (the -t option has other types as well) You can then copy the contents of this file to ~(remote-user)/. Ssh/authorized_keys on the remote machine. As the script user, you can test that it works by: ssh remote-user@remote-machine You should be logged in without a password prompt.

Along the same lines, now when your script is run from that user, it can auto SSH to the remote machine.

If you really want to use password authentication , you can try expect. See here for an example.

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