Operating System - Linux
1748269 Members
3684 Online
108760 Solutions
New Discussion юеВ

need help for use ssh in shell scripting

 
SOLVED
Go to solution
Karthik_sg
Frequent Advisor

need help for use ssh in shell scripting

how to use ssh in shell scripting so that the password and user name are given in the script itself and the control is not given out to the system.I want to install few rpm into the other system using the shell script pls.help.
thnks in advance.
9 REPLIES 9
Alexander Chuzhoy
Honored Contributor
Solution

Re: need help for use ssh in shell scripting

Best way is to copy the content of your public ssh key to the ~/.ssh/authorized_keys file on destination.
read here for more details:
http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html


or you can automate your login with expect script.
To learn about expect:
http://expect.nist.gov/
Karthik_sg
Frequent Advisor

Re: need help for use ssh in shell scripting

thanks,But now the control id given to the other syatem.I men to say that the control is passed to the other syatem command mode.pls help me execute this code.i tried copying the key u had sent but how to execute this code.

#!/bin/sh


ssh root@192.0.0.10;
rpm -Uvh /rpmfiles/*.rpm;

And 192.0.0.10 is the other machine.
Alexander Chuzhoy
Honored Contributor

Re: need help for use ssh in shell scripting

All you had to do is to get rid of the semicolon, so the code would look like this:

#!/bin/sh

ssh root@12.0.0.10 rpm -Uvh /updates/rpmfileswithdependencies/*.rpm;
Karthik_sg
Frequent Advisor

Re: need help for use ssh in shell scripting

hey thanks man,it relly worked.I can now install the rpms to the other machines in the same network.
Alexander Chuzhoy
Honored Contributor

Re: need help for use ssh in shell scripting

Actually you're not limited to the same network. You can install RPMs this way on any reachable via SSH machine (also through Internet).
Karthik_sg
Frequent Advisor

Re: need help for use ssh in shell scripting

hi,may i know how,I got a internet connection at home having an ip address10.0.0.2 and the office ip is 192.0.0.10.So how do i proceed.Pls do let me know.
Karthik_sg
Frequent Advisor

Re: need help for use ssh in shell scripting

hi,may i know how to install rpms to remote machines.I got a internet connection at home having an ip address10.0.0.2 and the office ip is 192.0.0.10.So how do i proceed.Pls do let me know.If possible pls explain it briefly.
Matti_Kurkela
Honored Contributor

Re: need help for use ssh in shell scripting

10.0.0.2 is a NATted address, so you cannot access it through the internet. All IP addresses that start with "10." are like this. There are other groups of addresses like this: the most well-known are "172.(16-31)." and "192.168.".

When you're back home, go to www.whatismyip.com: it's a website that reports your IP address as far as it can detect. I think it will not list your IP address as 10.0.0.2, but something else entirely.

The address displayed by www.whatismyip.com might be the address of your cable modem, ADSL router or whatever kind of network connection you're using. It might also be some device of your ISP.

If you can configure that device to forward the connections that arrive to port 22 (or some other port, if you want to be a little obscure) of the IP address shown by www.whatismyip.com to your local 10.0.0.2, you can then connect to your home computer using SSH from any place in the internet that does not block outgoing SSH connections.

WARNING: this means anyone else can try to connect to your home computer too. When you configure port forwardings like that, you're intentionally weakening the security shield provided by the NAT function. Being able to access your home computer through the internet is certainly cool, but having your computer used as a relay station for junk email or illegal activities is not fun at all.

There are worms and other malware on the internet that are constantly searching for SSH-accessible hosts with easily guessable passwords.

If you make your home computer SSH-accessible from the internet, *always* disallow direct logins as "root" user and ensure that all accessible accounts have strong passwords installed. Do this *before* you set up the port forwarding.

MK
MK
Karthik_sg
Frequent Advisor

Re: need help for use ssh in shell scripting

sry sgain,but how to forward the connections that arrive to port 22.what is forwarding a conection to port 22.explain briefly about ports also or provide any link to know this.waiting for ur reply.