hi, i have a shell script that needs to log onto a remote computer using ssh, how would i go about doing so? I tried #!/bin/sh ssh hostname -l username but then it prompts me for a password(obviously), how would i need to modify the script in order to input the password for me? Thanks..
Hi "anonymous", Welcome to JavaRanch! When you have a chance, click on the "My Profile" link up there and change your user name to something that meets the guidelines. There are two ways you can go here. One is to use "expect", a scripting tool that knows how to send data to processes that read directly from a tty device (most programs that read passwords do this.) The best way to learn expect is from the book. This would be useful for things that run unattended, like from a cron job. The other thing you can do is use ssh-agent. This is what I use to run CVS over ssh; couldn't live without it. This is a program that runs in the background and listens for requests for your SSH credentials, and supplies them to the programs that need them. The basic steps would be: 1) Set SSH up to use public key authentication when you log in to the remote machine. The details of how to do this vary depending on the version of SSH you're using and the version on the server. There are actually a lot of combinations, but generally, they all involve using ssh-keygen to generate a public/private key pair, then copying the public key onto the remote machine. 2) Run ssh-agent. The details of how to do this depend on what your login shell is; you have to run it in such a way that its output gets evaluated as shell commands. For bash on Linux you want to use "eval `ssh-agent`". 3) Use ssh-add to tell the ssh-agent instance what your passcode is; this allows it to supply your credentials to other programs that you run from this shell. 4) Now if everything has been done right, when you run ssh, it will ask ssh-agent for your credentials and won't need to prompt for a password.