Vagabond Shark

Ideas, Bikes, Art, Design, Architecture, Politics, Tech, Software

Trick of the day

Posted by Peter W on March 28, 2007

I was working on figuring out why a co-worker couldn’t use public key authentication over SSH today. While I was logged in as him, I didn’t want to mess up the rest of his SSH settings, so I used the following trick: make ~/.ssh look different for me than it does for him. Heres how:

First, make something to mount:
dd if=/dev/zero of=loop.img bs=1k 10000 # 10000 blocks of size 1k gives 10M
Create a loopback device with the loop.img file:
losetup /dev/loop0 loop.img
Next put an ext2 filesystem on it:
mke2fs -c /dev/loop0 10000
Now mount it on top of the .ssh directory:
mount /dev/loop0 .ssh
When finished, unmount and remove the loopback device:
umount .ssh
losetup -d /dev/loop0

Next time you want to mount it, just use mount (losetup not required):
mount -o loop -t ext2 loop.img .ssh

One important thing I found out: if you generate the SSH key (ssh-keygen -t rsa, ENTER, ENTER, ENTER) and copy it to authorized keys (cat ~/.ssh/ >> ~/.ssh/authorized_keys) but remote logins still aren’t working, ensure that the group doesn’t have write permission to .ssh (chmod go-w .ssh).


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: