Monday, October 18, 2010

Speed up SSH

Try setting up ssh client with compression and use arcfour/blowfish encryption instead. Also avoid ipv6 lookup and reuse connections using
socket:
Add below to ~/.ssh/config
Host *
Ciphers arcfour,blowfish-cbc
Compression yes
AddressFamily inet
ControlMaster auto
ControlPath ~/.ssh/socket-%r@%h:%p

Friday, October 15, 2010

Install your own git server on Cent OS / RHEL /Fedora

i386:
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
x86_64:
rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm
As root run this command:
yum install git
Next I’m going to setup a new repository and make it accessible over ssh:
mkdir /home/rajat/repo #create directory for new repository
cd /home/rajat/repo
git init
We’ll create a dummy file to get started. If you trying to clone (checkout) an empty git repository, you’ll just get errors:
touch firstfile
Add all files in this directory to your git repository:
git add .
Commit the changes you’ve made to the repo:
git commit
Next we’ll create a clone of the repo and configure it to be public:
cd /home/rajat
git clone --bare ./repo repo.git
touch  repo.git/git-daemon-export-ok
you can copy your repo.git directory to where you want to make the repo public
Now we want to checkout a copy of the new repository from a different server.
git clone ssh://yourserveraddress/home/rajat/repo.git
You should now have a new directory labeled repo which contains the file ‘firstfile’
To add a new file to the repo:
cd repo
touch secondfile
git add .
git commit
Now we want to submit the changes back to the git server:
git push
You’ll be prompted for your password.
:)

Linux / UNIX Delete or Remove Files With Inode Number


An inode identifies the file and its attributes such as file size, owner, and so on. A unique inode number within the file system identifies each inode. But, why to delete file by an inode number? Sure, you can use rm command to delete file. Sometime accidentally you creates filename with control characters or characters which are unable to be input on a keyboard or special character such as ?, * ^ etc. Removing such special character filenames can be problem. Use following method to delete a file with strange characters in its name:
Please note that the procedure outlined below works with Solaris, FreeBSD, Linux, or any other Unixish oses out there:

Find out file inode

First find out file inode number with any one of the following command:
stat {file-name}
OR
ls -il {file-name}

Use find command to remove file:

Use find command as follows to find and remove a file:
find . -inum [inode-number] -exec rm -i {} \;
When prompted for confirmation, press Y to confirm removal of the file.

Delete or remove files with inode number

Let us try to delete file using inode number.
(a) Create a hard to delete file name:
$ cd /tmp
$ touch "\+Xy \+\8"
$ ls

(b) Try to remove this file with rm command:
$ rm \+Xy \+\8
(c) Remove file by an inode number, but first find out the file inode number:
$ ls -ilOutput:
981956 drwx------  3 rajat admin 4096 2010-10-15 15:05 gconfd-viv
981964 drwx------  2 rajat admin 4096 2010-10-15 15:05 keyring-pKracm
982049 srwxr-xr-x  1 rajat admin    0 2010-10-15 15:05 mapping-viv
981939 drwx------  2 rajat admin 4096 2010-10-15 15:31 orbit-viv
981922 drwx------  2 rajat admin 4096 2010-10-15 15:05 ssh-cnaOtj4013
981882 drwx------  2 rajat admin 4096 2010-10-15 15:05 ssh-SsCkUW4013
982263 -rw-r--r--  1 rajat admin    0 2010-10-15 15:49 \+Xy \+\8
Note: 982263 is inode number.
(d) Use find command to delete file by inode:
Find and remove file using find command, type the command as follows:
$ find . -inum 982263 -exec rm -i {} \;
Note you can also use add \ character before special character in filename to remove it directly so the command would be:
$ rm "\+Xy \+\8"
If you have file like name like name "2009/12/31" then no UNIX or Linux command can delete this file by name. Only method to delete such file is delete file by an inode number. Linux or UNIX never allows creating filename like 2009/12/31 but if you are using NFS from MAC OS or Windows then it is possible to create a such file.



Remove Files and Directories with Special Characters

Today is going to be a practical tip. If you're managing many Unix/Linux systems, sooner or later you come across files with special characters – they can't be deleted with rm command using standard approach and require a bit of trickery to be successfully removed.

Examples of files with special characters

Any language apart from English will probably have special characters in the alphabet, but for the purpose of today's exercise I'll give you more standard examples: files starting with dash (-) and hash (#) characters:
rajat-linux$ ls -al
-rw-r--r-- 1 rajat admin    0 Sep 25 05:50 #try
-rw-r--r-- 1 rajat admin    0 Sep 25 05:48 -try
Now, if you try to access these files or remove them, you will get errors:
rajat-linux$ cat -try
cat: invalid option -- r
Try `cat --help' for more information.
rajat-linux$ rm -try
rm: invalid option -- t
Try `rm ./-try' to remove the file `-try'.
Try `rm --help' for more information.
These errors happen because commands treat file names as command line options because they start with dash (-).
With filenames starting with hash (#), you'll get a different kind of error: your Unix shell will treat the rest of a filename (and anything that might follow it) as a comment because hashes are used to do it in shell scripts. That's why your cat command will not show any error but will not finish until you Ctrl+C it:
rajat-linux$ cat #try
… and if you try removing such a file, you'll get a complaint from the rm command about missing command line parameters – because of the hash (#) sign, rm command receives no text as a parameter:
rajat-linux$ rm #try
rm: missing operand
Try `rm --help' for more information.

How to remove a file when filename starts with dash (-)

First I'm gonna show you how to make your Unix shell interpret any filename directly instead of trying to analyze it as a set of command line options.
To make command ignore the leading dash (-) in a filename, use the — command line option:
rajat-linux$ rm -- -try
As you can see, our file is gone:
rajat-linux$ ls -al
-rw-r--r-- 1 rajat admin    0 Sep 25 05:50 #try

Using backslash to escape special characters in a filename

Another option we have is to use a backslash (\), which will make shell interpreter ignore the special functionality of a character which immediately follows it. To escape the hash (#) our second file has, we should therefore do the following:
rajat-linux$ rm \#try
Interesting to know: bash shell has an auto-completion functionality built in. When you type a filename, just press Tab key to make it auto-complete the name for you. Speaking of special characters in particular, quite a few of them are recognized by auto-completion and get escaped automatically.
So, if you start typing:
rajat-linux $ rm #t
… and then press Tab, bash will not only auto-complete the name, but escape the leading hash (#):
rajat-linux $ rm \#try
There's a few more tricks you can use for escaping special characters, but they're worth a separate post, so stay tuned! Until then, enjoy getting rid of annoying files with special characters in filenames!