Tag: linux

How to Kill Multiple Processes with One Line in Bash

In bash:

Details on its workings are as follows:

  • The ps gives you the list of all the processes.
  • The grep filters that based on your search string
  • The awk just gives you the second field of each line, which is the PID.
  • The $(x) construct means to execute x then take its output and put it on the command line. The output of that ps pipeline inside that construct above is the list of process IDs so you end up with a command like kill 1234 1122 7654.

Source: http://stackoverflow.com/questions/3510673/find-and-kill-a-process-in-one-line-using-bash-and-regex

Changing the AWS Shell Prompt Without Affecting the Hostname

If you do not want to modify the hostname for your instance, but you would like to have a more useful system name (such as webserver) displayed than the private name supplied by AWS (for example, ip-12-34-56-78), you can edit the shell prompt configuration files to display your system nickname instead of the hostname.

Edit the file and change the shell prompt variable (PS1) to display your nickname instead of the hostname. Find the following line that sets the shell prompt in /etc/bashrc (several surrounding lines are shown below for context; look for the line that starts with [ “$PS1”):

And change the \h (the symbol for hostname) in that line to the value of the NICKNAME variable.

Log out and then log back in to pick up the new nickname value.

source: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-hostname.html

Retrieving the AWS Public Key for Your Key Pair on Linux

On a Linux instance, the public key content is placed in an entry within ~/.ssh/authorized_keys. This is done at boot time and enables you to securely access your instance without passwords. You can open this file in an editor to view the public key for your key pair. The following is an example entry for the key pair named my-key-pair. It consists of the public key followed by the name of the key pair.

You can use ssh-keygen to get the public key for your key pair. Run the following command on a computer to which you’ve downloaded your private key:

When prompted to enter the file in which the key is, specify the path to your .pem file; for example:

/path_to_key_pair/my-key-pair.pem

The command returns the public key.

If this command fails, ensure that you’ve changed the permissions on your key pair file so that only you can view it by running the following command:

source: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#retrieving-the-public-key

How To Install LAMP in Ubuntu

Step-by-step instructions on how to install LAMP (Linux Apache MySQL PHP) in Ubuntu.

Before we start, it’s best to do an update:

Apache

Install the webserver.

PHP5

Install PHP5 along with it’s apache module.

MySQL

Install MySQL along with it’s php and apache modules.

Then restart the server with:

Alternative, you can ignore everything above and just run the following commands:

Presumably, it just installs the same things, only with less typing copy pasting.

How to Install VirtualBox Guest Additions in Ubuntu Server 12.04

Had this Evernote’d, seems incomplete (and I don’t know how accurate it is) but I’ll post this anyway, might become useful one day…

To save my non geek readers, of which I don’t believe I have any (readers that is…) from having to scroll through blocks of useless code/jargon. Click the link below for what should be a fairly accurate step-by-step guide on how to install VirtualBox guest additions in Ubuntu Server 12.04, along with how to auto mount your shared folders.

Installing VirtualBox Guest Additions on Ubuntu Server 12.04

  1. sudo apt-get install dkms
  2. sudo apt-get install build-essential
  3. sudo apt-get install linux-headers-uname -r
  4. sudo reboot
  5. cd /media
  6. sudo mkdir cdrom [if doesn’t exist]
  7. sudo mount /dev/cdrom /media/cdrom
  8. cd cdrom
  9. ls
  10. Run the relevant installer:
  11. sudo ./VBoxLinuxAdditions.run

Auto mount shared folder

  1. comment out the share mounting lines in /etc/fstab
  2. edit the /etc/rc.local file [not the /etc/init.d/rc.local file] to add the mount points in the form of: mount.vboxsf -w HOST_FOLDER /MOUNT_POINT

e.g. my original /etc/rc.local file contained the following:

It now looks like this: