If you have an error with ssh client or server itself you should try with followings:

Firstly, you should set extra verbose messages on ssh client outputs with -vvv flag:

ssh -vvv user@host

There are quite usefullinformations in verbose output mode.

Secondly, you should take a look at ssh server logs or syslog records.

If you have a bit strange problem, you have to start another instance of ssh server with debugging enabled on unused port like that:

/usr/sbin/sshd -d -p 5656

and try to connect this instance with:

ssh -vvv -p 5656 user@host

Now you can see both of the client and server side messages. Ssh prints lots of useful information in debugging mode. If you want even more debuggin messages at server side, add another d flags and increase verbosity like that:

/usr/sbin/sshd -ddd -p 5656

 



To change time of the system in Linux, you can use date command on the prompt.

date --set=HHMM

where HH is Hour and MM is minute

 

Example:

date --set=2359

 will set the time of the system to 23:59

 

If you accidently create a file which names begins with a dash (-) character, you'll be realize that you can't simply delete this file with regular rm command:

rm -f -testfile
rm: invalid option -- t

Because of the first character is a dash, shell thinks we want to provide an option to rm commands itself. Solution of this problem is to use double dash character -- after our command's options are finished:

rm -f -- -testfile

it works. When -- character seen, shell thinks that optional arguments for command itself finished and doesn't make option parsing anymore.

 

SHA (Secure Hash Algorithm) is an algorithm and it is mainly used to verifying integrity of files under linux. Unlike MD5 (it is only 128 bits), SHA uses 160 bits by default (SHA1) and there is 4 another improved version:

sha224: 224 bits
sha256: 256 bits
sha384: 384 bits
sha512: 512 bits

You can learn sha1 sum of a file (160 bits) with:

sha1sum filename

or

shasum -a 1 filename

shasum uility takes -a parameter as 1, 224, 256, 384 and 512 repectively and make calculations for the specified bits length.

 

Making some kind of text search and replace operations on a single or multiple files is a trivial task for every Linux system admin or even normal user. There are different ways for this, we just want to describe two of them.

If you already familiar with perl and know a little regular expression syntax, you can use one-line embedded perl usage:

perl -pi -e 's/search/replacement/g;' *.txt

or combine with find and xargs:

find -name "*.html" | \
xargs perl -pi -e 's/search/replacement/g;'

read more

Tags: ls sort list size

There are lots of ways to list files and sort by their size with the help of pipe operator, for example:

ls -l | sort -n -k 5

But ls command already has builtin support for this:

ls --sort=size -l

you can reverse the list with -r option:

ls --sort=size -lr

or you may add -h (human-readable) parameter for good looking:

ls --sort=size -lrh

 

If you want to force fsck filesystem check on next boot, you can do this with creating an empty file with the name of  "forcefsck" on root directory:

touch /forcefsck

If you want to disable fsck running on the next boot, you can do this with creating an empty file with the name of "fastboot" on root directory:

touch /fastboot

Both files will be removed on next boot.

Tags: lsof netstat

lsof is one of the little known but very powerfull utility in Linux. Man pages basically says that lsof: list open files. But you can use it for managing and tracking network connections, you can list open ports, identify connections currently being made to your system, and determine what resources a process is using. Not only that, but you can also determine what processes a particular user has and find detailed information about file and directory usage. Here some example usages:

 

List all open files in system:

lsof

read more

If you can not mount your XFS partition with classical "wrong fs type, bad superblock etc." error and you see a message in kernel logs (dmesg) like that:

XFS: Filesystem sdb7 has duplicate UUID - can't mount

you can still mount the filesystem with nouuid options as below:

mount -o nouuid /dev/sdb7 disk-7


But every mount, you have to provide nouuid option. So, for exact solution you have to generate a new UUID for this partition with xfs_admin utility:

xfs_admin -U generate /dev/sdb7
Clearing log and setting UUID
writing all SBs
new UUID = 01fbb5f2-1ee0-4cce-94fc-024efb3cd3a4

after that, you can mount this XFS partition regularly.



If you forget your root password, you can easily reset it by entering some options into grub loader when system is being loaded. After system reset, and some bios check, Grub is loaded and there are some choices from which kernel or operating systems to boot.

 

read more