Email: bknpk@hotmail.com Phone: +972-54-7649119


V

 

ASIC/FPGA Design and Verification Out Source Services

Remote Connecting To Work Computer

Sometimes there is a need to connect to the office and work from home. All that is required is an ability to SSH to home computer. From home of course you can't SSH to work (otherwise you just do ssh -C -X from home).

  1. First at work I open a tunnel:
    ssh -X -R 2222:localhost:22 my_user@79.100.100.1
  2. at home the following command is used:
    ssh -C -X pinik@localhost -p 2222
  3. Setting up the display:
    In general there should not be any error and ssh -X should take care of setting up the display. I had to do, however, the following: I edited the following file displaymanager at /etc/sysconfig:

  4. # Tcp port 6000 of Xserver. When set to "no" (default) Xserver is
    # started with "-nolisten tcp". Only set this to "yes" if you really
    # need to. Use ssh X11 port forwarding whenever possible.
  5. #Pini to allow work from remote
    #DISPLAYMANAGER_XSERVER_TCP_PORT_6000_OPEN="no"
    DISPLAYMANAGER_XSERVER_TCP_PORT_6000_OPEN="yes"
  6. Once I logged into the office computer, the DISPLAY variable was changed by the default .cshrc. Since I had no permission to the file, I had to find out what did the ssh -X got for the DISPLAY. I did it by logging into the office with bash, since bash is not used at the office:

  7. ssh -C -X pinik@localhost -p 2222 "bash -i"
  8. echo $DISPLAY
  9. localhost:18.0
  10. ssh -C -X pinik@localhost -p 2222
  11. setenv DISPLAY localhost:18.0

  12. Add to the remote ssh config file the following lines. It will send a keep a live message to avoid a link cut down.
    vi ~/.ssh/config
    Host *
      ServerAliveInterval 60
      StrictHostKeyChecking no

  13. It might be necessary in some cases to disable the xserver nolisten tcp option.
    /etc/X11/xinit/xserverrc
    As an example one can consider working with LSF. If the job is interactive, the LSF job needs a communication link with the x-server. In that case also do the following:

    Add run server to the host list.
    xhost + 179.68.171.44
    Run BSUB command to open an simple xterm or gvim on a remote server:
    bsub -Ip xterm -display 179.68.168.185:0.0
    bsub -Ip 'bash -c "export DISPLAY=209.68.168.217:0.0;gvim"'

  14. For those who don't have a constant IP address. You must to figure out a way to remotely copy your IP. This is shown in the following example:

    Also you need to be able to ssh without password using RSA keys.
    run, on the office machine, the following command, using an empty passphrase:
    ssh-keygen -t rsa
    copy the the information to your home machine:
    cat ~/.ssh/id_rsa.pub | ssh pini@79.178.38.206 'cat >> .ssh/authorized_keys'
    You also may need to copy the file ~/.ssh/authorized_keys to ~/.ssh/id_rsa.pub.


    Also since this is a script, we need to cancel the confirmation for a new entry in the known hosts file. If you have a constant IP, don't include it (second line in the confirmation file).
    See also Connecting to a remote system via ssh without a password. .

    If the SSH server disconnects you, add to your ~/.ssh a config file with the following entry:(indention is a must)
    Host *
      ServerAliveInterval 60
      StrictHostKeyChecking no

    #!/bin/bash

    wget http://bknpk.dynu.com/my_web >& 1.txt
    v_ip=`grep "Resolving .*bknpk" 1.txt | perl -e '$i=<STDIN>;if($i =~ /(Resolving .*bknpk.*\.\.\.)(.*)/) {$j=$2; $j =~ s/ //g;chomp($j);print("$j\n");}'`
    #echo $v_ip
    #ConnectTimeout=43200
    v_comm="ssh -X -R 2222:localhost:22 guestA@"$v_ip" -o ConnectTimeout=99999"
    echo $v_comm

    #clean up
    \rm -f *.html 1.txt
    #connect
    $v_comm

    #some message
    echo "start loop"
    date
    sleep 2


    i="0"
    while [ $i -lt 15 ]
    do

      wget http://bknpk.dynu.com/my_web >& 1.txt
      v_ip=`grep "Resolving .*bknpk" 1.txt | perl -e '$i=<STDIN>;if($i =~ /(Resolving .*bknpk.*\.\.\.)(.*)/) {$j=$2; $j =~ s/ //g;chomp($j);print("$j\n");}'`
      #echo $v_ip
      #clean up
      \rm -f *.html 1.txt
      v_comm="ssh -X -R 2222:localhost:22 guestA@"$v_ip" -o ConnectTimeout=99999"
      pgrep -f -x "$v_comm" > /dev/null 2>&1 || i=$[$i+1]
      pgrep -f -x "$v_comm" > /dev/null 2>&1 || $v_comm

      echo "continue loop "$i" times"
      date

      sleep 5
    done

  15. When using cygwin to SSH to a remote machine, GUI application stops to work after some time. As an example for running the X application xclock, I got the following error:
    X connection to localhost:11.0 broken (explicit kill or server shutdown).
    This can be easily overcome by adding the -Y (Enables trusted X11 forwarding) option to the SSH command (in addition to -C -X).

  16. An improved version of the script can be taken from: connect bash script
  17. Some old operation systems don't support the option of ServerAliveInterval . In that case the following script can be used: loop and send data evry 30 seconds script

  18. Last sometimes I need to kill all current outside connections and let the script at work re-connect. Since more than link may involve, it is better done with a script.
    The script both automate the operation and avoids errors, such as killing the shhd server itself. The script is shown in the next page.
  ...


Home

Download Area






Search This Site


Feedback This Site




new pages on this site