linux - ssh "port 22: no route to host" error in bash script -


i wrote scipt execute couple of ssh remote comands relating apache storm. when execute script says:

ssh: connect host xxx.xxx.xxx.xxx port 22: no route host ssh: connect host xxx.xxx.xxx.xxx port 22: no route host ssh: connect host xxx.xxx.xxx.xxx port 22: no route host ssh: connect host xxx.xxx.xxx.xxx port 22: connection refused 

if execute commands manually works out , can ping machine. there has wrong code:

while [ $i -le $numvm ]      if [ $i -eq 1 ];then         ssh -i file root@ip1 './zookeeper-3.4.6/bin/zkserver.sh start'      else         ssh -i file root@ip2 'sed -i '"'"'s/#\ storm.zookeeper.servers.*/storm.zookeeper.servers:/'"'"' /root/apache-storm-0.9.3/conf/storm.yaml'         ssh -i file root@ip2 'sed -i '"'"'0,/^#[[:space:]]*-[[:space:]]*\"server1\".*/s//"      - \"'${iparray[1]}'\""/'"'"' /root/apache-storm-0.9.3/conf/storm.yaml'         ssh -i file root@ip2 'sed -i '"'"'s/#\ nimbus.host:.*/"nimbus.host: \"'${iparray[2]}'\""/'"'"' /root/apache-storm-0.9.3/conf/storm.yaml'         ssh -i file root@ip2 './zookeeper-3.4.6/bin/zkcli.sh -server ${iparray[1]} &'         sleep 10         ssh -i file root@ip2 './apache-storm-0.9.3/bin/storm nimbus &' &         sleep 10         ssh -i file root@ip2 './apache-storm-0.9.3/bin/storm ui &' &          sleep 10         ssh -i file root@ip2 './apache-storm-0.9.3/bin/storm supervisor &' &     fi       ((i++)) done 

i'm starting several processes on 2 virtual machines deployed same image, identical in general. confusing part is, first ssh command (zkserver.sh start) working if script tries execute 3 "sed"-ssh-commands error message above. last 4 ssh-commands working out again. not make sense me...

several things can think of:

  • most sshd daemons won't allow root access. heck, many versions of unix/linux no longer allow root login. if need root access, need use sudo.
  • the sshd daemon on remote machine isn't running. although rare, sites may never had setup, or purposefully shut off security issue.
  • your ssh commands incorrect.

instead of executing ssh commands in shell script, modify shell script print out you're attempting execute. then, see if can execute command outside of shell script. way can determine whether problem shell script, or problem ssh command itself.

if ssh commands don't work outside command line, can simplify them , see if can determine issue be. have ssh -i file root@ip2. suppose ssh -i $file root@$ip2? (i.e., you're missing leading sigil).

$ ssh -i file root@$ip2 ls   # can't simpler this... $ ssh -i file root@ips       # see if can remotely log on... $ ssh root@ip2               # try without 'identity file' $ ssh bob@ip2                # try user other 'root' $ telnet ip2 22              # port 22 open on remote machine? 

if these don't work, have basic issue setup of remote machine's sshd command.


Comments