Slackware mini How to and various tricks II

 General  Comments Off on Slackware mini How to and various tricks II
Sep 032011
 

Check the previous article too.

How to change the default port value for SSH to listen to?

Go to /etc/ssh/sshd_config and change the line saying

Port 22 # < --- this line to something else. e.g. 2222
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

Restart SSH daemon by invoking  /etc/rc.d/rc.sshd restart as root. This will make SSH to listen to port 2222.

How to make colorful grep command?

Suppose you like the Ubuntu’s colorful grep command. It’s actually very easy to be made on every Linux flavor. You need to alias the grep command this way:

alias grep='grep --color'

This ways grep will always be with option –color. And you need to set the color:

export GREP_COLOR=';32m'

;32m” here means green. But you may prefer other color. They are:

red 31
green 32
yellow 33
blue 34
magenta 35
cyan 36
white 37

If you want those settings remembered, enter the 2 lines for alias and export at the end of your ~/.bashrc file. That’s all.

How to make Xfce4 to support Cyrillic keyboard?

Put the following in the file /etc/X11/xorg.conf

Section "InputDevice"
 Identifier  "Keyboard0"
 Driver      "kbd"
 Option      "XkbModel" "pc105"
 Option      "XkbLayout" "en,bg"
 Option       "XkbOptions" "grp:alt_shift_toggle"
 EndSection

The option XkbLayout can also say [ru], [ua] or other Cyrillic using nations. The Option to set the button to Alt+Shift can also be changed.

The next step is to set your window manager to show the state changes. You only need to install the package xfce4-xkb-plugin.

How to change forgotten root password!?

I suppose it is YOUR own machine, and you are not trying to ruin it for someone else.

It’s a bit tricky if you don’t have root access to the machine. It can take forever to brute force a password with CLI or over SSH. I frankly don’t recommend this method. It’s for forgetful idiot script kiddies.

The only method good enough is if you have physical access to the machine.

Reboot with a live CD (or live USB stick). Your root file system is probably /dev/hdc or /dev/sda1. If unsure – use cfdisk and see which partition is made bootable. This is probably your root partition. Mount the filesystem in any mount point (e.g. /mnt/hdc).

mount /dev/hdc /mnt/hdc

Have a look at the file /mnt/hdc/etc./shadow. The file should look like this:

root:$1$w4BtrTq5$4NwUXg/ite/GysUCmaHf6.:15114:0:::::
bin:*:9797:0:::::
daemon:*:9797:0:::::
adm:*:9797:0:::::
lp:*:9797:0:::::
sync:*:9797:0:::::
...

Now… The first method is to clean everything in the first line from the $ (dollar sign) to the first : (colon sign) so it looks like the other lines below. But this will leave your machine vulnerable to anyone, because your root account will not have password. SSH forbids passwordless logins, but a little healthy paranoia is never in excess. Execute the following 2 commands:

adduser idiot
passwd idiot

Confirm the adduser dialog with dummy data. It’s temporary user after all.
Enter any password for the user “idiot” we just made and have a look at the live CD’s temporary  /etc/shadow file:

bash-4.1# cat /etc/shadow | grep idiot
idiot:$1$.Zf3P/ya$SISp/sFHX.gLPGKMDv5HJ1:15220:0:99999:7:::
bash-4.1##

We have the new password hash (or encrypted password if you like it more). We copy the string starting from the $ (dollar sign) up to the first : (colon sign) without the colon sign itself in the /mnt/hdc/etc/shadow file replacing the hash written there for root password.

That’s all. You only need to reboot the machine and remove the live CD. Your new root password is set.

*(The hash shown here is for the password “alabala” and It is for an example only. I don’t recommend using such short and weak palindrome for password.)

 Posted by at 3:53 pm

Solving a Sudoku, part II.

 Gam3s  Comments Off on Solving a Sudoku, part II.
Sep 032011
 

If you are unfamiliar with the game, or this method is a bit advanced to you – please see my previous article about the 2 basic methods.

If you try to solve this grid by using the “Dim view” you will go almost nowhere. You will find some of the probable number positions and few exact positions. Of course, we feel lucky, and we may try.

This method is a bit more hard, I call it

Blocked squares

If you start using baby steps or dim view on this grid, you will end up with a grid filled with pencil scratches, some of them very useful, and some of them completely useless, until late game. You should of course, always give it a try with simpler and faster methods and then introduce some logic. The very basic trade of this method is to sweep a hard or very hard grid and point the possible numbers in any 3×3 area so you can block some of the squares inside.

Blocked squares

Blocked squares

Having a look in this scratched-a-bit grid on right, you will easily notice that left area of top plane has its bottom 3 squares with only possible numbers 1, 7 and 9. Rightmost area of same top plane has above 2 missing numbers either 7 or 9. Both of those areas leave us with some 4 more squares to guess, and some of those 4 squares are half solved.

Middle area of middle  plane has 2 blocked squares with either 1 or 3.

Bottom plane has it’s bottom left area with blocked numbers 3 or 4 and rightmost top are with line filed with 3, 4 or 8.

One more time

One more time.

This is not really helping much by first glance, but let’s repeat the procedure again and recheck this time only the areas with some blocked squares by baby steps, number by number. Having this passed again, you find, that the bottom plane has number 2 in 4 possible positions. Write them down and don’t mess with this method anymore for now, but keep it in mind for a bit later. It’s useful to have a pencil to write probable numbers, before making them with a pen. If you use pen directly, you may get the stuff wrong.

Lines and crosses

If you look at the grid above you will see it’s really going to fit in category very hard. It has only one possible solution, and it is suitable to explain  this method, because the 3 method explained so far … fail to make any number to it’s place. The name of the method explains almost everything. We find a line that has more than 3 numbers in it and try to build up from there.

Having a look at all the candidates in the grid with all the blocked squares, few things pop up.

  • There are rows with more numbers either written or probable.
  • There are columns with more numbers either written or probable.
  • There are crosses formed from those rows and columns.

What does that mean? Probably some easy numbers will pop up 🙂

First number

First number solved

Have a very careful look at topmost row 1. We have the following: X,8,6,5,5,1,7/9,3,7/9. 4 known numbers. 2 blocked squares. 2 positions with probable 5’s and one completely unknown. Missing numbers 2 and 4. Now we have a look at the numbers below. First square of this row can hold only 2 or 4 and 4-th square of the same row can also hold only 2 or 4 (have a good look at the columns). This leaves one of the squares with probable 5 obsolete and the next square beside it – absolutely certain. Can hold 5 and nothing more, because the other 2 missing, non-blocked squares will hold 2 or 4 and this exact square already has the numbers 2 and 4 in the 5-th column, so they CAN’T stand there.

Congratulations, we have the first number. We write it down and tap our shoulder proudly.

This one is particularly hard. It took me 1 (one) hour and I have made 4 errors. Will leave it this way, so you try your luck 😉

 Posted by at 9:59 am