This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

linux ssh help  RSS feed

Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a shell script that needs to log onto a remote computer using ssh, how would i go about doing so? I tried
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?
author and iconoclast
Posts: 24203
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!