- SSH into your server
- Run “ssh-keygen -t rsa” to generate a public and private key pair
- It will ask you where you to save the files. I recommend “/root/.ssh/bitbucket”
- It will ask you to choose a passphrase. Since we’re just using this for deployments, you can leave the passphrase blank. If a hacker manages to steal these files, they probably have access to the code on your server anyway (which is all that this key will give them access to).
- Run “cat /root/.ssh/bitbucket.pub”. It will spit out your newly generated public key. Copy it to your clipboard.
- On bitbucket.org, go into your repo settings, click “Deployment keys” on the left and paste in your new key
- Run “nano /root/.hgrc”
- Add this to the file:
[ui] ssh = ssh -i /root/.ssh/bitbucket [trusted] users = www-data
- cd into your project directory
- “hg clone ssh://firstname.lastname@example.org/NAME/PROJECT .” (The trailing dot clones into the current directory if you’ve already created it — make sure it’s empty or this won’t work)
- It should clone succesfully now. You can “hg pull && hg up –clean” whenever you like without any passwords. This might not be the most robust way to deploy, but it’s quick and easy.
Substitute “root” for your username if you SSH in as someone else.