Category Archives: Linux - Page 5

How to reset qmailadmin password. And do bulk user deletion.

Today nobody can revise password to our corporate mail server Control Pannel. Powered by qmail. With qmailadmin as WEB frontend.

How to change password to postmaster@randomthemes.com
/usr/local/vpopmail/bin/vpasswd postmaster@randomthemes.com

And other issue:
Where to write rcpthosts – /usr/local/qmail/control/rcpthosts

How to make a bulk user deletion:
issue was to delete 80 000 users ๐Ÿ™‚

mysql> select pw_name from vpopmail_randomthemes.vpopmail where pw_domain='randomthemes.com';
add users to file vpusers.txt and delete using vdeluser
# for i in `cat vpusers.txt | awk {'print $1 "@randomthemes.com"'}`; do /usr/local/vpopmail/bin/vdeluser $i; done;

How can I run dnsmasq DHCP/TFTP-only.

I mean disable DNS caching feature.
dnsmasq required by lxc to configure network, but I prefer to use bind, to provide DHCP resolver.
So use force, Luke! I mean read man.

-p, --port=<port>

Listen on <port> instead of the standard DNS port (53). Setting this to zero completely disables DNS function, leaving only DHCP and/or TFTP.

vi /etc/dnsmasq.d/lxc
port=0

Linux ext4 fs tuning

There is only 3 values affecting mostly affecting io perfomance.
noatime – don`t store file access time
Nodiratime – don`t store disk access time

And turn off journal!
tune2fs -O has_journal -o journal_data_writeback /dev/sdaX
or
data=writeback

my fstab

/dev/md/2 / ext4 noatime,nodiratime 0 0

But thereis no magic… if your have serious io problems – this will not help you. Tuning can give up to 10% perfomance.
usually less.

additional info
http://kerneltrap.org/node/14148

Some mysql howto

This topic was done to skip googling in some cases.

How to get mysql database size:

mysql -uroot -pPASSWORD -D DATABASE_NAME -e "show table status\G"| egrep "(Index|Data)_length" | awk 'BEGIN { rsum = 0 } { rsum += $2 } END { print rsum }'

Source: http://eddnet.org/?p=1765

How to set mysql to read only mode:
Attention! root can do r/w regardless of read_only!

mysql> set GLOBAL read_only = true;

edit config

:/etc/mysql/conf.d# cat slave.cnf
[mysqld]

server-id = 18
innodb_buffer_pool_size = 200MB
read_only = true

How to drop user

DROP USER 'USERNAME'@'%';

How to find duplicate rows.

SELECT *,count(id) AS Num FROM clicks_log GROUP BY id HAVING (COUNT(id) > 1 );

How to delete duplicated Rows
I am not SQL guru, maybe there is another perfect way how to do it, but it`s works:

mysql> create table id_tmp AS (SELECT id FROM block_news_views_log GROUP BY id HAVING (COUNT(id) > 1) ) ;
mysql> DELETE  FROM block_news_views_log WHERE ( id IN (SELECT * from id_tmp ) );
mysql> DROP table id_tmp;
mysql> SELECT id FROM block_news_views_log GROUP BY id HAVING (COUNT(id) > 1) ;

Ubuntu 12 USB monitor Display Link

Finally we have
xserver-xorg-video-displaylink I`ll try to run third monitor ๐Ÿ™‚
But it gives Green Screen ๐Ÿ™
Damn, not working.

How to verify your domain for GooGle Apps using bind

Damn, dudes from google didnt write howto for verification via bind nameserver.
It`s very very easy, just use @ as record name
Example:

am2# cat randomthemes.com
$ORIGIN .
$TTL 3600       ; 1 hour
randomthemes.com           IN SOA  ns1.randomthemes.com. root.randomthemes.com. (
                                2012052404 ; serial
                                3600       ; refresh (1 hour)
                                900        ; retry (15 minutes)
                                604800     ; expire (1 week)
                                3600       ; minimum (1 hour)
                                )
                        NS      ns1.randomthemes.com.
                        NS      ns2.randomthemes.com.
                        NS      ns3.randomthemes.com.
                        A       87.242.73.112
                        MX      1 ASPMX.L.GOOGLE.COM.
                        MX      5 ALT1.ASPMX.L.GOOGLE.COM.
                        MX      5 ALT2.ASPMX.L.GOOGLE.COM.
                        MX      10 ASPMX2.GOOGLEMAIL.COM.
                        MX      10 ASPMX3.GOOGLEMAIL.COM.

$ORIGIN randomthemes.com.
*                       CNAME   randomthemes.com.
www                     A       87.242.73.112

@       IN      TXT     "google-site-verification=XXXXXXXXXXXXXX-XXXXXX-XXXXXX-XXXXXXXXXXXXXX"

It`s working o.k.!

FreeBSD how to search and install apps from ports

Of course everyone know, how to do it. ๐Ÿ™‚ except me, old Linux geek. ๐Ÿ™‚
First, search for it, second install

ms2# whereis nmap
nmap: /usr/ports/security/nmap
ms2# cd /usr/ports/security/nmap
ms2# make install

Read more »

show open ports FreeBSD

In Linux I usually use

#netstat -4nlp

In FreeBSD syntax is different, your should use something like this:

#netstat -atn | grep LISTEN
or
#sockstat -l

Lenovo UEFI dual boot Windows7 Ubuntu

Today I had a real brainfuck, how to make Ubuntu and Windows 7 to coexist on my Lenovo Z570.
First I try grub-efi

 convert EFI partition to Fat32
 mount /dev/sda1 /boot/efi
 grub install /dev/sda
 
 mkdir /boot/efi/efi/boot/
 cp /boot/efi/efi/debian/grubx64.efi /boot/efi/efi/boot/bootx64.efi

Gentoo booting O.k., but I cannot make Windows 7 boot.
I copy windows loader efi from Windows/Boot/EFI And BCD (data for loader) at the same folder, and try custom menuitem at grub
It looks like this

menuentry "Win7" --class windows --class os {
  insmod part_msdos
  insmod fat
  set root '(hd0,msdos1)'
  search --no-floppy --fs-uuid --set root MY_UUID_FS
  chainloader $({root})/EFI/Microsoft/BOOT/bootmgfw.efi
}

Damn it`s not working. I`m talking about this wrong ways for you not to try this.

The only way how i make dual boot working.

1. Replace grub-efi with grub-pc (non efi grub build)
aptitude update && aptitude install grub-pc
2. install grub to linux partition my – /dev/sda6
3. Make it boot from Windows loader.

There is 2 way how to make it boot from Windows loader.
1. Use easybcd. (this will install grub4dos fork or other grub fork to load ubuntu from /dev/sda6)
2. Use windows native loader. Here are instructions for Windows 7 (there is no boot.ini at windows7 BCD used instead)

dd if=/dev/sda6 of=/mnt/share/linux.bin bs=512 count=1
bcdedit /create /d โ€œUbuntuโ€ /application BOOTSECTOR
BCDEdit will return an alphanumeric identifier for this entry that I will refer to as {ID} in the remaining steps. Youโ€™ll need to replace {ID} by the actual returned identifier. An example of {ID} is {d7294d4e-9837-11de-99ac-f3f3a79e3e93}. Next, letโ€™s specify which partition hosts a copy of the linux.bin file:
bcdedit /set {ID} device partition=c:
The path to our linux.bin file:
bcdedit /set {ID}  path \linux.bin
An entry to the displayed menu at boot time:
bcdedit /displayorder {ID} /addlast
and finally, letโ€™s specify how long the menu choices will be displayed:
bcdedit /timeout 30

It`s working! Now I have dual boot at this UEFI damned notebook!

How to remove backdore at inittab, left by ISP

Suddenly I found backdore at our servers, leaved by our dedicated server provider, I will not say it`s name, because we already talk to them, get a big discount and solve this issue.
If their engineer press Alt+ArrowUp he obtain a root console, without login record displayed by lastlog.
dump-utmp help ๐Ÿ™‚

r: ~ #aptitude install acct
  r: ~ # dump-utmp /var/log/wtmp

And here is a backdore:

r: ~ # cat /etc/inittab | grep kbre                                                                                                                
  #kb::kbrequest:/bin/echo "Keyboard Request--edit /etc/inittab to let this work."                                                                          
  kb::kbrequest:/sbin/getty -n -l /bin/bash tty12 115200                                                                                                    
  r: ~ #

How to remove it.

 #!/bin/sh
 
  for v in ` mkipsec -l |  awk '{print $1}' | sed s/:/\ / | tr -d '\n' | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g"`;
  do
    s=`echo $v|sed 's/.*\.//'` ;
    printf "$s :\n";
    ssh -q -t  $s "sed -i s/kb\:\:/\#kb\:\:/ /etc/inittab" ;
  done