LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-27-2007, 04:33 AM   #1
vdx
Member
 
Registered: Aug 2007
Location: The Greate INDIA
Distribution: CentOS, RHEL, Fedora
Posts: 102

Rep: Reputation: 24
Unhappy remote login via ssh (without interaction)


Friends,

I am developing a network application. So I have to login into remote PCs one by one and do some sort of work.

I am programming in C lang and distro is fedora 6.

For the remote login I m using SSH.

But wen I execute command "ssh <host ip>" programmatically then it asks me for the password entry. (expects pass entry from STDIN).

What I want is, non interactive password entry. Means If I have to interact with 5 client nodes then I have a text file which has IP addresses and corresponding passwords stored in it, and at the time of password entry it should read from text file, not prompting me on stdout for password entry !!

I know if u set ssh keys accordingly then it will not ask for password but for that also U must have to go through interactive password prompt for first time.

I heard about the pseudo terminals. One of my friend told me that if u use pseudo terminal then u can solve your problem.

but how, I dont know !! (I wanna do this programmatically)

plz help me. Is there any good link or tutorial or example program ??

any kinda help will be appriciated.

thnx
 
Old 09-27-2007, 05:23 AM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Libexpect can do this sort of stuff.

See this page.
 
Old 09-27-2007, 06:41 AM   #3
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
Take a look at man ssh-keygen.

You'll need to generate a public key without a passphrase (just hit the return key when prompted) and copy that to the home directory's .ssh/authorized_keys file on the remote machines. When you ssh server, you won't be asked for a password.

Also, in the .ssh directory (on your controlling machine) create a file config with content like this for every machine you ssh to:
Code:
Host remote-host-name
ForwardX11 yes
Compression yes
Protocol 2,1
User remote-user-name
It would be useful to enter the remote host name(s) is /etc/hosts while you're at it.

When you execute ssh-keygen on a machine, two files will be created in the .ssh directory: id_dsa and id_dsa.pub. The id_dsa file is the private key, the id_dsa.pub file is the public key (the one that gets copied to a remote machine). Once done, login is not required.

Note, however, that the first time you connect to any machine with ssh you will be prompted to add an entry in known_hosts for the machine you're connecting to (no convenient way around that one).

Again, see man ssh-keygen.
 
Old 09-27-2007, 06:59 AM   #4
vdx
Member
 
Registered: Aug 2007
Location: The Greate INDIA
Distribution: CentOS, RHEL, Fedora
Posts: 102

Original Poster
Rep: Reputation: 24
Cool

thnx matthewg42

u have suddgested me the exact point i m expecting.

thnk u very-very much.
 
Old 09-27-2007, 07:33 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
expect is a horrible solution *if* there are formal application specific ways to do this instead.. use preshared ssh keys and you will have a much better solution.
 
Old 09-27-2007, 07:46 AM   #6
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Quote:
Originally Posted by acid_kewpie View Post
expect is a horrible solution *if* there are formal application specific ways to do this instead.. use preshared ssh keys and you will have a much better solution.
Acid is quite right, expect is not generally a good solution for automating logins with ssh since there is already an existing mechanism and you will have to store the passwords somehow, and doing this is likely to be insecure. I mentioned expect only because the OP asked specifically about pseudo terminals.

I did actually once write a login manager/convenience tool using expect, which used ssh, rsh and even telnet, but boy did I feel dirty doing it...
 
Old 09-27-2007, 02:52 PM   #7
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
well yeah it's often a bit of a guessing game whether you answer the actual question or the question that you think they should be asking...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Remote login with SSH, but display on remote computer. brodin Linux - Software 3 09-09-2007 03:01 AM
ssh remote login sKAApGIF Linux - Networking 4 11-22-2006 07:13 AM
KDE Remote Login through SSH timothyb89 Linux - General 2 07-07-2006 06:03 PM
ssh remote login help LAdProg2005 Linux - Networking 2 10-05-2005 12:39 PM
I need remote login/ ssh/ whatever BryanMC Linux - General 6 05-26-2003 11:09 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration