An IP Address changed and now I can’t pull with Mercurial! Hjelp!

No worries! There are a few things you can do to resolve this speed bump in your race to code. I’ll walk you through a sample “WTF?!” session and the resolve things as we go along…

1. You run

hg pull

and get an error like this:

remote: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
remote: @    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
remote: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
remote: IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
remote: Someone could be eavesdropping on you right now (man-in-the-middle attack)!
remote: It is also possible that the RSA host key has just been changed.
remote: The fingerprint for the RSA key sent by the remote host is
remote: e4:42:f2:a3:94:2g:69:55:5a:21:87:b3:4d:bb:74:62.
remote: Please contact your system administrator.
remote: Add correct host key in /root/.ssh/known_hosts to get rid of this message.
remote: Offending key in /root/.ssh/known_hosts:1
remote: RSA host key for 192.168.1.100 has changed and you have requested strict checking.
remote: Host key verification failed.
abort: no suitable response from remote hg!

2. After going “WTF?!” you realize that the IP address being used by hg pull has changed so of course there is an error. There are probably better way to actually add the correct host key as directed in the error but for me the easiest was to simply open /root/.ssh/known_hosts and delete the keys present. Don’t do this unless you know you can regenerate new keys with no problem (the ideal way would be to add the correct key as directed but I don’t know how to do that without Google and was in a hurry).

3. The next problem is that hg pull is pointing to the wrong location. To change this you can edit the default path in the hgrc file (located in the .hg directory inside your project) to point to the correct URL. Should look like:

[paths]
default = ssh://username@192.168.1.100//location/of/your/project/

4. Now you should be able to do your pull!


Protip: Install a private/public key pair so you don’t have to log into ssh!

// generate the needed keys
ssh-keygen -t rsa
//that puts the key pair in your .ssh directory.
//In my Ubuntu machine that is at /home/myname/.ssh/

//copy the id_rsa.pub key from that machine
//to your remote machine's .ssh directory
scp /home/myname/.ssh/id_rsa.pub username@192.168.1.100:/Users/myname/.ssh

Now move over to the remote machine:

//that file needs to go into a file called authorized_keys
//(you may have to create this thus the touch command below)
cd /Users/myname/.ssh/
touch authorized_keys
cat id_rsa.pub >> authorized_keys

//now protect that with some strict permissions
sudo chmod 500 authorized_keys

Now you can make SSH connections (which pull is using) between these machines without having to supply a password each time.

     

No Comments

OpenVPN Setup tips

To send all traffic over an established VPN connection:

sudo iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o eth0 -j MASQUERADE
sudo -s echo “1″ > /proc/sys/net/ipv4/ip_forward
sudo openvpn /etc/openvpn/server.conf

     

2 Comments

SSH Tunneling Tips: Now With More Awesome!

OK, that previous tip was pretty weak. Try this instead. Set up a SOCKS proxy and tunnel it through SSH!

Here’s how:

1. Open the SSH connection…
ssh -ND 8887 -p 22 rufus@83.27.411.896

2. Set your network to point to the proxy. On a Mac that would be…
a. Open Network Preferences…
b. Click Advanced…
c. Click Proxies…
d. Check the SOCKS Proxy box then in the SOCKS Proxy Server field enter localhost and the port you used (8887)
e. OK and Apply and you are done!

p.s. Bonus! You can enable gzip compression by setting the -C flag (ex. ssh -C -ND 8887 -p 22 rufus@83.27.411.896)

     

No Comments

SSH Tunneling Tips

To tunnel one, single website over SSH:
ssh -L 8887:google.com:80 -p 22 -l rufus -N 83.27.411.896

Explanation:

The first port, 8887, is the one on your local machine that you are going to point your proxy to….
… next comes the website you are visiting…
… next is the port of the service on the remote computer you will be accessing
Web: HTTP 80
Web over SSL: HTTPS 443
Outgoing email: SMTP 25
Incoming email: POP3 110
Incoming email: IMAP 143

… next comes the port your SSH is set to (default is 22)…
… next is the user you will log in as…
… next is the address of the ssh server you are accessing.

That’s it. But you only gain access to Google. Try to go outside of that and you will get sent back to Google.

     

No Comments

Mercurial – pushing changes to a remote site

OK, this was not straight forward but it was mainly because of paths and permissions issues.

My local repository is here: /Applications/MAMP/htdocs/aproj/

On the remote machine I need to get a copy of this so I issue the following:
sudo hg -v clone ssh://me@192.168.1.107//Applications/MAMP/htdocs/aproj/ /var/www/aproj/
This will clone the repository.

After making changes I try to push them from the local repo to the remote server using:
sudo hg push ssh://me@192.168.1.105//var/www/aproj/

but this will fail with the error:
remote: Not trusting file /var/www/aproj/.hg/hgrc from untrusted user root, group root
remote: Not trusting file /var/www/aproj/.hg/hgrc from untrusted user root, group root
remote: abort: could not lock repository /var/www/aproj/: Permission denied
abort: unexpected response: empty string

This stems from the local repo having different owner (and group?) from the remote.

I can, however, do a pull from the remote repo (note I am inside var/www/aproj/:
sudo hg pull

Then update to implement the pulled changes:
sudo hg update

and that gets things working for the time being.

One really weird thing I ran into. on the local machine I can issue a command to mercurial with no problem. For example:
hg info
However, doing that via ssh from the remote server failed with the message that ‘hg could not be found’. The path to hg was set correctly (as evidence by ‘echo $PATH’) but I still had to symlink hg from /usr/bin/ in order to get it to work (from the remote machine… it worked fine locally).

Update: how to fix the untrusted user error… in your .hgrc add:
[trusted]
users=*
groups=*

     

2 Comments

Enable Color in Mac OS X Terminal

Want to colorize your ls output in Terminal? Stick this in your ~/.bashrc or ~/.bash_profile files:

export CLICOLOR=1

While you are at it add this alias to include invisible files in ls:
alias ls='ls -la'

Oh! One more useful one… to reload your .bash_profile without quitting and restarting the shell:
source ~/.bash_profile

     

No Comments

The iTunes Window Extends Off Screen and I Can’t Resize It, Help!

So you thought you could click the little plus button at the window’s top left corner (the green one unless you use the alternate Mac color scheme) to resize and you discovered that that only opens a tiny control panel?

Here is the big secret… hold down the option key while clicking the button with the plus on it at top left. Done! I love easy.

     

1 Comment

Change an Ubuntu server’s timezone from the command line

This is pretty straight forward. Log in to the system and type:
dpkg-reconfigure tzdata

Follow along as it prompts you. Bam. Done.

     

, ,

1 Comment

Wrap many lines of text in list item tags using RegEx

So I have an email with a huge list of names. They are displayed one per line. I want to wrap them in list item tags so I can stick them in an unordered list. Here is how to do it fast and painlessly…

First, here is what I start with (just imagine 1000 names, rather than 3):

Bob Smith, Acme Corp, CEO
Janet Johnson, Barton Inc, VP for Development and Shoe Sizes
Cat Sims, Transmo Inc, VP of Conference Room Chair Height Adjustments

Here is the regex I will find and replace with:
Find:

(.*)\r

Replace (pretend that last “\r” is right next to the list item closing tag:

  • \1
  • \r

    The find code looks for anything with a carriage return at the end and then grabs the bit in the parenthesis.
    The replace code wraps that bit in the parenthesis (signified by the \1), wraps it in list item tags and sticks a carriage return on the end.

    Now my list looks like:

  • Bob Smith, Acme Corp, CEO
  • Janet Johnson, Barton Inc, VP for Development and Shoe Sizes
  • Cat Sims, Transmo Inc, VP of Conference Room Chair Height Adjustments
  •      

    No Comments

    Basic secure file copying using SCP

    Securely copy a file from one computer to another (in this example on my local network):
    $ sudo scp stuart@192.168.1.100:Downloads/somefile.iso /home/stuart/downloads

    This will copy the file somefile.iso that is in my remote computer’s home dir’s Download directory ~/Downloads/ or put another way as the remote computer is a Mac /Users/stuart/Downloads/ over to the local computer’s dir at /home/stuart/downloads/

         

    No Comments