Monday, April 28, 2014

Simple socks proxy with ssh

SSH can be used to create a simple socks proxy.

Just establish a connection from your local machine to an other computer with a running ssh server:
ssh -D 9292 user@host
 After that, setup your browser to use the local ssh redirect to connect to the internet.


That's all, you can check your IP address with a service like: http://geoiptool.com/ now.


Saturday, June 8, 2013

How to move your linux (archlinux) installation to a new hdd

There are several methods to do this. This method simply copies all files from HDDold to HDDnew, reinstalles the bootloader and that it.
1. Boot a livecd (archlinux install iso will do ("loadkeys de" to 
     switch keyboard layout))
2. mount /dev/sdOLD /mnt/old (ex. /dev/sda1) (fdisk -l)
3. mount /dev/sdNEW /mnt/new (ex. /dev/sdb1)
4. cp -rav /mnt/old/* /mnt/new
4.1 Or you can use rsync: rsync -avH /mnt/old/ /mnt/new/
    rsync can exclude directories:
    rsync -avH --exclude '/mnt/old/home/porn' /mnt/old/ /mnt/new/
5. umount /mnt/old
Thats it for now, all files are on our new disk.
(If you are on archlinux and use syslinux as your bootloader of choice you can skip 6.1 - 6.5)

We now have to chroot into our new copy to be able to install grub.
6.1. mount -o bind /dev /mnt/new/dev
6.2. mount -t proc none /mnt/new/proc
6.3. chroot /mnt/new /bin/bash
Grub installation:
6.4. grub-install /dev/sdNEW
6.5. exit
Syslinux installation:
(make sure you are not in a chroot environment. The archlinux syslinux script supports installing syslinux in a mounted linux environment.)

7.1.  syslinux-install_update -a -i -m -c /mnt/new
Thats it, we are done.

8. Exit and reboot
Make sure to remove your old harddrive and put the new one to the same SATA port, so it will get the same device name in linux.


Saturday, April 6, 2013

Save file in vim as root even when you opened it as user


:w !sudo tee %

w ! takes the file content and pipes it into the following shell command
sudo tee (the shell command)  sudo opens tee as superuser and tee writes the input to a given parameter
% (the given parameter) is replaced with the current filename

Wednesday, August 15, 2012

vim settings / tricks i use


Here are some settings i personally use.
I will extend this post as soon as discover more.

/etc/vimrc
syntax on (syntax highlighting)
set number (line numbers)
set keywordprg=perldoc\ -f (shift-k opens perldoc for item under cursor )

to be continued

Saturday, August 11, 2012

Extended bash tab completion

Just install the package "bash-completion" in archlinux und you will get extended tab completion for the following programs: http://wklej.org/id/808581

*edit: Make sure  "/etc/bash.bashrc" is up-to-date otherwise it may not work.

Even tab completion for rsync and scp remote files structures works now.

Monday, July 30, 2012

Bash prompt shortener

Add this to your ~/.bashrc
# Bash shortener
_PS1 ()
{
    local PRE= NAME="$1" LENGTH="$2";
    [[ "$NAME" != "${NAME#$HOME/}" || -z "${NAME#$HOME}" ]] &&
        PRE+='~' NAME="${NAME#$HOME}" LENGTH=$[LENGTH-1];
    ((${#NAME}>$LENGTH)) && NAME="/...${NAME:$[${#NAME}-LENGTH+4]}";
    echo "$PRE$NAME"
}
PS1=' \[\e[0m\]\u\[\e[0;32m\]@\[\e[0m\]\h \[\e[0;32m\]$(_PS1 "$PWD" 30) \[\e[0m\]$ '
It will shorten the path in your bash prompt to 30 chars.

Saturday, January 7, 2012

Start applications with the default app from console

Its as simple as. Add this to your ~/.bashrc
alias open='nohup xdg-open >/dev/null 2>&1'
 Now you can start, for example a textfile, like this "open textfile.txt". Because of nohop in the alias you can even close the console session and the text editor stays open.