Install python 3 in Ubuntu 12.04

Ubuntu 12.04 ships with python 2.7, whereas 12.10 comes with python 3 by default.

Check installed version:
python -V

Install python 3 from python development ppa:
sudo add-apt-repository ppa:python-dev/ppa
sudo apt-get update
sudo apt-get install python3.3

Check all available python versions:
ls -l /usr/bin/python*

Remove the symlink to 2.7:
sudo rm -i /usr/bin/python

Create a symlink to python 3:
sudo ln -s /usr/bin/python3.3 /usr/bin/python
python -V

Revert the symlink if you ever need to go back to older version of python.

Advertisements

Vim Navigation

h j k l
Basic navigation

0(zero)
Go to the start of current line

^
Go to the first non blank character of current line

$
Go to the end of current line

g_
Go to the last non blank character of current line

nG
Jump to line n

Ctrl f
Jump forward one full screen.

Ctrl b
Jump backwards one full screen

Ctrl d
Jump forward (down) a half screen

Ctrl u
Jump back (up) one half screen

Ctrl o
Jump backwards (out) through the jump list

Ctrl i
Jump forward (in) through the jump list

L
Jump to bottom of screen (low)

M
Jump to middle of screen (middle)

H
Jump to top of screen (“high”)

zt
put this line at the top of the screen

zb
Put this line at the bottom of the screen

zz
Put this line at the middle of the screen

More: http://www.thegeekstuff.com/2009/03/8-essential-vim-editor-navigation-fundamentals/

Repair/Restore/Reinstall Grub with Ubuntu Live CD

Grub is a Linux bootloader which can boot all conceivable operating systems. Occasionally you will find yourself with a broken grub if you are spending a lot of time in Linux. Specially if you have Windows alongside Linux, re-installing Windows will wipe out grub.

To fix grub with Ubuntu live CD, boot the system from the live CD and open up a terminal.

Step#1. Mount Ubuntu partition

sudo fdisk -l
sudo mount /dev/sdXY /mnt

Replace XY. In my case it is /dev/sda1
If you are not sure where you installed Ubuntu, fdisk or gparted will show all the available partitions in your system. Ubuntu installation should be in a ext4 Linux partition.

Step#2. Mount boot partition(only if you have a separate boot partition)

sudo mount /dev/sdYY /mnt/boot

Replace YY. In my case I do not have a separate boot partition.

Step#3. Mount virtual filesystems(for step 4)

sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys

Using bind mounts, we can mount all, or even part of an already-mounted filesystem to another location, and have the filesystem accessible from both mount points at the same time[1].

Step#4. chroot
Chroot is the process of changing of the apparent disk root directory (and the current running process and its children) to another root directory. When you change root to another directory you cannot access files and commands outside that directory. This directory is called a chroot jail. Changing root is commonly done for system maintenance, such as reinstalling the bootloader or resetting a forgotten password[2].

sudo chroot /mnt

Now we are in the chrooted environment!

Step#5. Install, check, and update grub

grub-install /dev/sdX
grub-install --recheck /dev/sdX
update-grub

Replace sdX with your boot device. ‘grub-install’ command will perform a complete re-installation of grub.

Step#6 Exit chroot and unmount

exit
sudo umount /mnt/dev
sudo umount /mnt/proc
sudo umount /mnt/sys
sudo umount /mnt/boot
sudo umount /mnt

Unmount boot partition only if you followed step 2

Step#6 Reboot
sudo reboot -h now

References:
1. http://docs.1h.com/Bind_mounts
2. https://wiki.archlinux.org/index.php/Change_Root

Setting up OpenSSH Server in Ubuntu

sudo apt-get install openssh-server
pgrep sshd

Review configuration and make changes wherever necessary. Default protocol is ssh2, listen port is 22 and listens to all ipv4 and ipv6 addresses.
sudo vim /etc/ssh/sshd_config

Try it out :
ssh 127.0.0.1

If you plan to ssh over the internet and you have firewall enabled, make sure to allow incoming request at ssh listen port.

sudo ufw status
sudo ufw allow 22
sudo ufw status

If you have dynamic ip and want to use a ddns mapper like dyndns or dlinkddns, you will need configure ddns setting and forward ssh port in the router.

#Check if the port is being forwarded properly:
http://www.canyouseeme.org/
#Check if are able to ssh over the internet:
https://www.serfish.com/console/

Now you can access your home computer form work!

SSH security: http://www.cyberciti.biz/tips/linux-unix-bsd-openssh-server-best-practices.html
Disable password login: http://lani78.wordpress.com/2008/08/08/generate-a-ssh-key-and-disable-password-authentication-on-ubuntu-server/

Finding Files in Linux

find /media/music/ -type d -iname '*metallica*'
Finds all directories with ‘metallica’ in the name within the given path. ‘iname’ makes it case insensitive.

find /media/music/ -type f -iname '*fade*to*black*.mp3*'
Finds all mp3 files of ‘fade to black’.

Install VirtualBox in Ubuntu 12.04

wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -

sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian precise contrib" >> /etc/apt/sources.list'

sudo apt-get update && sudo apt-get install virtualbox-4.1

Successful installation will create ‘vboxusers’ group. Add currently logged in ubuntu user to ‘vboxusers’ group.

sudo adduser $USER vboxusers

Adding Users in Ubuntu

1. adduser
sudo adduser john
Prompts for each piece of information(password, home dir etc)

To create/assign admin/sudoer:
sudo adduser john admin
If john already exists, it assigns admin/sudoer privilege to john. This works because /etc/sudoers is pre-configured to grant permissions to all members of this group.

2. useradd
sudo useradd john
Adds user without any extra options. User won’t have a password or a home directory.
To create user with home dir:
sudo useradd -d /home/john -m john
To change password:
sudo passwd john

Check man pages of adduser and useradd for additional options.