title: ssh executed from a script hop and X11 forwarding
body: <p>I am working on a small cluster with computation nodes and 2 master nodes. I can connect from my local machine to the masters or directly to the computation nodes using a ssh hop. Here is my .ssh/config on my local machine:</p>
  
  <pre><code>Host master0
       HostName 132.166.138.122
       User OJ239416
  
  Host master1
       HostName 132.166.138.121
       User OJ239416
  
  Host node*
       ProxyCommand ssh -Y master1 nc %h %p
       User OJ239416
  </code></pre>
  
  <p>Once connected to any computation or master node, I can move to another node using this script (in order to preserve environment and working directory):</p>
  
  <pre><code>#!/usr/bin/env sh
  
  if [[ $# != 1 ]]; then
      echo 'USAGE:'
      echo '  sssh remotename'
      exit 1
  fi
  
  DIR=$PWD
  
  printenv | sed -e '/_=.*/ d;s/\([^=]\+\)=\(.*\)/export \1="\2"/' &gt; $HOME/.sssh-env.txt
  echo "$PWD" &gt; $HOME/.sssh-pwd.txt
  ssh -X $1
  </code></pre>
  
  <p>with this in my .bashrc:</p>
  
  <pre><code>if [ -f "$HOME/.sssh-env.txt" ]; then
      source $HOME/.sssh-env.txt
      cd $(cat $HOME/.sssh-pwd.txt)
      rm $HOME/.sssh-env.txt
      rm $HOME/.sssh-pwd.txt
  fi
  </code></pre>
  
  <p>What does not work: if I connect from my local machine to a master node and then move to another node using my script, I got no display. </p>
  
  <p>Something funny is that if I connect to a computation node from my local machine and then move to another computation node with the script, it works (but not if from a computation node I go to a master node...).</p>
  
  <p>Thanks for helping!</p>