LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   SSH connection to remote machine... (https://www.linuxquestions.org/questions/linux-networking-3/ssh-connection-to-remote-machine-597176/)

harishkrishnan 11-04-2007 11:19 PM

SSH connection to remote machine...
 
Hi All,

I have a question on SSH...
If we do an ssh connection to a remote linux machine, it will ask for a password. Once password is entered, we will be able to login...

Ex: ssh root@<IP_Addr>
password:

So, what iam looking for is, i should be able to pass the password from the script or a single command. The user should not be asked for password.

I tried the following options....but it din't work.

- echo <passwd> | ssh root@<IP Addr>
- ssh root@<IP Addr> --stdin <passwd>

Kindly help me on this...

Note: I know about sharing the keys and avoid asking password itself.

Wim Sturkenboom 11-05-2007 12:26 AM

You can use authentication based on a key pair. Edit the sshd config and set the password authentication to no (as shown below).

Code:

# To disable tunneled clear text passwords, change to no here!
#WimS
PasswordAuthentication no
#PasswordAuthentication yes

Next the user needs to generate a keypair.

Code:

wim@btd-techweb01:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/wim/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/wim/.ssh/id_rsa.
Your public key has been saved in /home/wim/.ssh/id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx wim@btd-techweb01

The private key needs to be carried to the clients that need access. I copied it to a memory stick so I can access the server from 'any' location; no memory stick, no access.

If you omit the passphrase, the user will not be prompted for the passphrase.

Some other advise:
  • limit the users in the config; if user A does not need access, config the server so he/she can not use SSH
  • in general you should not use direct root access; access the server as a normal user and next su to root or use (sudo to elevate privileges). Everybody knows that there is a root user and will try to hack that account.

complich8 11-05-2007 12:59 AM

ssh won't read a password from a piped stdin.

If you're really dedicated to not using a key pair, consider writing an expect script to do what you want.

ssh-agent may also be a viable answer.

harishkrishnan 11-06-2007 08:58 PM

Thanks Wim & Complich...

But tell me, does this Key pair work for Solaris also ? .i.e from local Linux box, i have to execute commands of remote Sun box.

complich8 11-06-2007 11:27 PM

Quote:

But tell me, does this Key pair work for Solaris also ? .i.e from local Linux box, i have to execute commands of remote Sun box.
Absolutely.

If you're trying to execute remote commands without going to a full shell, then you can specify the command you're trying to execute on the ssh command line -- eg:
Code:

ssh you@yourhost commandtoexecute
If you've got the same set of commands you're trying to execute on the remote system, you might consider turning them into a simple shell script. Similarly, if it's something that's going to happen at regular intervals, you may consider a cron job on the remote machine rather than having the local machine constantly poke it.

harishkrishnan 11-10-2007 12:35 AM

Thanks much....Looks like i can get some more ideas frm you people..

Here is what iam doing & expecting ur help on this...

See, i am doing an GUI appln in Linux using QT. We have a product which works on all the unix flavours(..Lin, Sun, Mac, HPux...)
The GUI application which am doing is bascically a testing tool which helps in testing this product.
So far what i have made is a standalone application i.e. it works only on a single Linux box. Now am working on extending this application for testing products on remote machines(Lin, Solaris, MAC) also.
So this is the actual requirement!

Few of the features of this appln are like viewing the log files, filtering the contents, viewing system properties, stop/start of product services...and some more.
-------------------------------------------------

So am assuming that, what all commands i have used to run on local machine, i can use the same commands for remote Linux machines also using - "ssh you@yourhost commandtoexecute" right? (with appropriate commands for Solaris, mac...)

I would definitely ask many questions as i progress on this..
Thanks very much in advance...


All times are GMT -5. The time now is 04:46 AM.