Category Archives: Terminal / Shell

My OSX Bash Shell prompt

I’m rather fond of my bash prompt:

export PS1="\n`tput setaf 6`\w/    `tput setaf 7`(\u@\h)`tput sgr0`\n\$ "

it prints my full path,  then shows me who I am and on which (short) domain.. then on the next line.. a simple indicator as to if i’m root or not .. then the cursor..

Setting this permanently

  1. Change to your home directory cd ~
  2. Make / Edit your .bash_profile file by typing edit .bash_profile
  3. paste the export line into this text file and save it.
  4. All done!
phpMyAdmin screenshot

Connecting to your WordPress Database with phpMyAdmin from an OSX Remote Machine

If you are using a Bitnami WordPress (multisite) stack like I am, your web-based database phpMyAdmin is setup by default to only be accessible if you are on the same machine (IP address of 127.0.0.1:80).

So in order to get access remotely, you have to trick your machine into thinking you are local.  Thankfully there is some documentation on how to do all of this… but the following is a succinct summary.

  1. Beforehand, setup your .pem keyfile in your keychain, or add -i path/to/your.pem in the following ssh command.
  2. In Terminal, type ssh -N -L 8888:127.0.0.1:80 bitnami@yourdomain.com
    • Unfortunately, when this command runs successfully, there is no text shown.. 
  3. In a web browser, go to http://127.0.0.1:8888/phpmyadmin/
  4. The default credentials for a Bitnami stack are “root” and a password of “bitnami”

When you are done, you can just kill your SSH connection with a Control-C.

shell script shirt

How to create an executable shell script in OSX or Linux

I am a complete novice at times when it comes to shell commands. So there are some commands that are SO basic, that I should feel ashamed to blog about them… but this site is just as much for my reference as it is for yours 😛

  1. Make a text file in a text editor
  2. Type some commands in it as you would manually in your terminal
  3. Save the file as something like your-file-name.sh
  4. In terminal, navigate to yoru saved file and type chmod a+x your-file-name.sh
  5. When you want to run this script, navigate to it and type ./your-file-name.sh  (It is very important to prefix your file with ./ or else it won’t execute.)
Make it yourself!

HOW TO : Setup your own freaking personal WordPress server!

Muhahaha!The fact that you are reading this means I did it. I finally got off my bum.. stopped using my crappy Tumblr blog and worked out how to use Linux, SSH, Amazon EC2 and how to change my own DNS. It took all of my free time when I wasn’t looking after my baby to get it going, but it was worth it because now I have complete control!!!

Muhahaha!!

Simple Steps:

  1. Setup the server.
  2. Write this post for the next person.

More Detailed Steps:

Now, you can make your own Linux image, and then install your WordPress on it, but why bother?

Install a Bitnami-made WordPress image on Amazon’s Elastic Compute Cloud

  1. Go to http://bitnami.org/stack/wordpress#cloudImage and scroll down to the “Amazon machine images”
  2. Click on an Ubuntu 64-bit EBS link.. you can use either single site which is a touch easier, or multisite (like I did) which I felt was built ready for what I wanted.
  3. Select a T1 Micro-sized machine, and Launch Instance (you could request a launch instance, but it’s more complicated)
  4. Keep clicking Continue until you get to the screen that talks about Key Pairs. If you already have a key pair generated, select the one you want. If not, generate a new one.
  5. When setting up security groups, make one that can accept incoming connections on ports: 22 (SSH), 3389 (RDP), 5900 (VNC), 80 (HTTP), 8080 (HTTP alt)
  6. Click Launch!
  7. Wait for it to boot and the State to change to “Running”.. then click on it and scroll down and copy the Public DNS address
  8. Paste the public DNS value into your web browser and navigate to it. If everything went right, a web page should show!

Connect to it!

  1. Download your Key Pair file from Amazon. Mine is called Linux.pem. This file is your password file. You won’t be typing in a password, you will be supplying this file.
  2. In a terminal window (OSX), change to the directory you downloaded your Linux.pem file and type chmod 600 Linux.pem (This will allow this file to be used)
  3. Now connect to your remote machine with ssh -i Linux.pem bitnami@xxxxxx (where xxxxxx is the Public DNS). If you want to stop having to specify your Linux.pem file.. consider having a look at this article.


RSA pem key - blurred

Storing my pem key file in my keychain to mount a filesystem with SSH

My problem is that I’m not very go at vi Editor 🙁

I used to be ok at it, but really, for now, I’m rubbish at it.

I figured there had to be some lovely program that would mount my remote machine’s drive via SSH… AND THERE IS!

So i’m trying ExpanDrive‘s 30 day trial for their program that will reliably mount and re-mount remote file systems.

Their #1 issue so far is that their documentation is pretty sucky.
Their #2 issue is that it’s not obvious how to connect to a filesystem via SSH when you have to use a .pem file.

Thanks to this StackOverflow article, I found out I can add my Linux.pem key to my keychain.

  1. type ssh-add -K /path/to/private/key/file.pem
  2. In ExpanDrive, create a connection to your server with your login and leave the password field blank. Your pem passphrase will be read from the keychain.
  3. In terminal, you can now connect via SSH with ssh bitnami@yourdomain.com without having to specify the location of your pem file (previously ssh -i path/to/Linux.pem bitnami@yourdomain.com)
Configuration dialog for ExpanDrive

Configuration dialog for ExpanDrive

When my 30 day trial ends, I may play around with using Cyberduck or OXFUSE or sshfs-gui.

OSX Transmit

I had a license to the program Transmit and I tried it out and it is AMAZING at connecting to SFTP resources, and mounting them as local drives and synchronization.  Get it!  I can’t recommend it enough!

UPDATE

I almost lost my Linux.pem key! This would have been an epic screw up, but fortunately I remembered that I have a backup of the file on Dropbox. Unfortunately dropbox also strips off unix permissions, and ssh requires the pem key to have a permission of 400 (not public).

When I tried connecting with a file that was “too open” i got the following

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for 'Linux.pem' are too open.
It is recommended that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: Linux.pem
Permission denied (publickey).

The solution?

Make the file less “open”… to do this one need only type:
chmod 400 Linux.pem

Installing wget on OSX

My parents have a dynamic website that hasn’t been updated in about 3 years. So I figured it was time to host their site on a less expensive static host… but first I had to download their static webpages!

I had heard wget was the program to use for that, but its not a standard OSX command line tool, so I found an excellent article to build it on my own machine.

http://thomashunter.name/blog/install-wget-on-os-x-lion/

Once I got that working i downloaded a static version of their dynamic site with the following
wget -m -p http://www.site.com/