• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

linux ssh help

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Aaaaaand ... we're on the march. Stylin. Get with it tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic