Mar. 12th, 2010

joshua0: (Default)
OK, so, for a while, I've had this alias:

alias linux='ssh -Y 172.16.187.130'

which sshes into my Linux VM on my Mac, and either gives me a shell or runs a command. In general, it's nice and transparent:
joshua@escape:~/school/hotc/proj$ uname -a
Darwin escape.joshuawise.com 10.2.0 Darwin Kernel Version 10.2.0: Tue Nov  3
10:37:10 PST 2009; root:xnu-1486.2.11~1/RELEASE_I386 i386 i386 MacBookPro5,5
Darwin
joshua@escape:~/school/hotc/proj$ linux uname -a
Warning: No xauth data; using fake authentication data for X11 forwarding.
Linux escape-ubuntu 2.6.31-16-generic #53-Ubuntu SMP Tue Dec 8 04:02:15 UTC
2009 x86_64 GNU/Linux

But sometimes, I want to jump over into Linux to run a few commands in that environment, and I want to go back and forth between OS X and Linux. I found that there's one particular issue with this alias that punches through the smoke and mirrors pretty badly:
joshua@escape:~/school/hotc/proj$ linux
[...]
joshua@escape-ubuntu:~$ pwd
/home/joshua
joshua@escape-ubuntu:~$ :(

How annoying. So, as any good hacker would (and also because I didn't want to actually work on my HOT compilation project), I set off to fix this. I found that there's an ssh option, SendEnv, and a corresponding sshd option, AcceptEnv. These can be used to transport an environment variable containing some arbitrary data -- in my case, the current directory on my Mac -- over the SSH link.

The first step if you want to do this is to enable environment forwarding on the other end. Edit your /etc/ssh/sshd_config file, and at the end of the AcceptEnv LC_* LANG line, add the name MACD, and restart your sshd. Then, on the Mac side, change your alias to:

alias linux='MACD=$(pwd) ssh -Y -o SendEnv=MACD 172.16.187.130'

This will export the Mac directory to the other side. On the other side, in your bashrc, drop the lines (or something like):
if [ "$MACD" != "" ]; then
        if (echo "$MACD" | grep "^/Users/joshua" >/dev/null); then
                MACD=$(echo "$MACD" | sed \
                        -e 's#^/Users/joshua/projects#/home/joshua/projects#' \
                        -e 's#^/Users/joshua/school#/home/joshua/school#' \
                        -e 's#^/Users/joshua#/home/joshua/osx#')
        else
                MACD="/mnt/hgfs/root$MACD"
        fi
        cd "$MACD"
fi

You'll want to change the regexps for your own mount points, and enable remote filesystem mounting in VMware.

Now, given this:
joshua@escape:~/school/hotc/proj$ linux
Warning: No xauth data; using fake authentication data for X11 forwarding.
Linux escape-ubuntu 2.6.31-16-generic #53-Ubuntu SMP Tue Dec 8 04:02:15 UTC 2009 x86_64

160 packages can be updated.
93 updates are security updates.

Last login: Fri Mar 12 02:00:52 2010 from escape.local
joshua@escape-ubuntu:~/school/hotc/proj$ ls
project-1  project-1.tar  project-2  project-2.tar  project-3  project-3-bin.Linux.tar.gz  project-3.tar

Perfect! Now, to actually do my HOTC project...
Page generated Aug. 24th, 2025 12:57 pm
Powered by Dreamwidth Studios