Empulse Group a collection of notes from a sys admin, musician, and father

12Aug/12Off

VIM tips

Here are tips for moving around in VIM while in command mode:
press 0 (zero) to jump to the beginning of the line
press $ to jump to the end of the line
press :7 to jump to line 7
press gg to jump to the beginning of the file
press G to jump to the end of the file
press dd to delete the current line
press u to undo
press control+r to redo
press yy to yank (copy) the current line
press P to put (paste) before the current line
press p to put after the current line
press /string to search for "string" in the file, going forward
press ?string to search for "string" in the file, going backwards
press n to repeat search in same direction
press N to repeat search in reverse direction
press :noh to clear you search to remove highlighting
press :%/search/replace/g to replace each instance of "search" with "replace"
press A to insert after the end of line


Tagged as: , , Comments Off
6Feb/12Off

LVM expand

Use 'parted' to partition the new array with a single LVM physical partition.

[root@www ~]# parted
(parted) mklabel gpt
(parted) mkpart
Start? 0
End? -1Partition name?  []? primary
File system type?  [ext2]?
Start? 0
End? -1
(parted) print
(parted) set 1 lvm on
(parted) print
(parted) quit
[root@www ~]# pvcreate /dev/sdb1

Expand the / logical volume into the new space in the volume group.

[root@www ~]# vgextend vglocal20120206 /dev/sdb1
[root@www ~]# lvextend /dev/vglocal20120206/root00 /dev/sdb1

Grow the file system with tune2fs or ext2online.

[root@www ~]# resize2fs /dev/mapper/vglocal20120206-root00
15May/110

rsync

To sync contents of two directories using rsync.

 

Access via remote shell:

Pull: rsync [OPTION...] [USER@]HOST:SRC... [DEST]

Push: rsync [OPTION...] SRC... [USER@]HOST:DEST

 

-v, --verbose increase verbosity

-a, --archive archive mode; equals -rlptgoD (no -H,-A,-X)

-u, --update skip files that are newer on the receiver

--existing skip creating new files on receiver

--ignore-existing skip updating files that exist on receiver

-z, --compress compress file data during the transfer

 

 

 

SYNC: pull, then push data

 

PULL: rsync -avz --ignore-existing test1@empulsegroup.com:/home/test1/Documents .

PUSH: rsync -avz Documents test1@empulsegroup.com:/home/test1

 

22Feb/110

Tricks with iptables

Use iptables to force mail out a specific ip address:

[root@www ~]# iptables -t nat -A POSTROUTING -p tcp --dport 25 -j SNAT --to-source 192.168.100.123

Rate limit port 80, 100 connection limit:

[root@www ~]# iptables -A INPUT -p tcp --syn --dport 80 -m connlimit --connlimit-above 100 -j DROP
8Jan/110

50 UNIX / Linux Sysadmin Tutorials

50 UNIX / Linux Sysadmin Tutorials.

2Jan/110

Journal Aborted

1. Blow away the journal.

[root@www ~]# tune2fs -O ^has_journal /dev/hda5

1a. If this fails because of the needs_recovery flag, you will need to run the following.

[root@www ~]# debugfs -w /dev/hda5
debugfs: features ^needs_recovery
debugfs: quit

Again, try to blow away the journal.

[root@www ~]# tune2fs -O ^has_journal /dev/hda5

2. Now, you can fsck the partition.

[root@www ~]# fsck.ext2 -f /dev/hda5

3. Rebuild the journal.

[root@www ~]# tune2fs -j /dev/hda5
15Nov/100

Setting up vsftpd with MySQL authentication

Here we will be setting up vsftpd to use MySQL for authentication using pam_mysql.  MySQL already uses PAM so we will just need to edit the pam file for this service to use the pam_mysql module. Then, we edit the vsftpd.conf file. And finally, the user credentials will be stored in a MySQL database.

Install packages:

  • pam_mysql
  • mysql
  • vsftpd
[root@www ~]# cat /etc/pam.d/vsftpd
auth required /lib64/security/pam_mysql.so user=vsftpd passwd=foo host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=passwd crypt=0 sqllog=1 logtable=logs logmsgcolumn=msg logusercolumn=user logpidcolumn=pid loghostcolumn=host logrhostcolumn=rhost logtimecolumn=logtime
## i will just space these 2 lines out ##
account required /lib64/security/pam_mysql.so user=vsftpd passwd=foo host=localhost db=vsftpd table=users usercolumn=name passwdcolumn=passwd crypt=0 sqllog=1 logtable=logs logmsgcolumn=msg logusercolumn=user logpidcolumn=pid loghostcolumn=host logrhostcolumn=rhost logtimecolumn=logtime

Note: For the crypt=x option, the following applies
-------
0 = No encryption. Passwords in database in plaintext. NOT recommended!
1 = Use crypt
2 = Use MySQL PASSWORD() function

[root@www ~]# grep -v \# /etc/vsftpd/vsftpd.conf
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
nopriv_user=vsftpd
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
guest_enable=YES
guest_username=vsftpd
local_root=/home/vsftpd/$USER
user_sub_token=$USER
virtual_use_local_privs=YES
chroot_local_user=YES

Then we need to create a 'vsftpd' system user. Our virtual ftp users will have home directories under /home/vsftpd. We also have to manually create the home directory for the virutal users as specificed by the "local_root" directive in the vsftpd.conf file.

[root@www ~]# useradd --home /home/vsftpd -m --shell /bin/false vsftpd
[root@www ~]# mkdir /home/vsftpd/test3
[root@www ~]# chown vsftpd:vsftpd /home/vsftpd/test3/

CREATE DATABASE AND TABLES IN MYSQL

> create database vsftpd;
> use vsftpd;
> create table users (id int AUTO_INCREMENT NOT NULL, name char(128) binary NOT NULL, passwd char(128) binary NOT NULL, primary key(id) );
> create table logs (msg varchar(255), user char(128), pid int, host char(128), rhost char(128), logtime timestamp );
> INSERT INTO users (name, passwd) VALUES ('test5', 'test5'); // for plain text, crypt=0 in /etc/pam.d/vsftpd
> insert into users (name, passwd) values ('eric@empulsegroup.com',password('tististis')); // when using MySQL PASSWORD() function or crypt=2 in the pam file

21Apr/090

Nice Cacti Install How To

RedHat / CentOS Install and Configure Cacti Network Graphing Tool

16Apr/090

Reset file permissions of RPM packages

UPDATE: YOU NEED TO RUN THE FOLLOWING COMMANDS IN REVERS ORDER!

So, --setperms then --setugids. This is because setperms will overwrite sticky bits if run after setugids.

A disastrous mistake anyone can make on their Linux server is to chown or chmod their entire filesystem.

You can reset the permissions of packages installed with rpm.

To reset file permissions:

[root@www ~]# rpm --setperms {packagename}

To reset ownership permissions:

[root@www ~]# rpm --setugids {packagename}
4Apr/090

One-Liners

Search for multiple processes in one command. Example in using multiple variables.

[root@empulse ~]# ps auxf | grep -P '(wincompd:|proftpd:)'

Lower the reserved disk space to 0%. By default Linux will reserve 5% of each file system as reserve free disk space.

[root@empulse ~]# tune2fs -m 0 /dev/hda5 remove reserved space

Compare two files on two remote file systems. I saw this on Command-line-fu.

[root@empulse ~]# diff <(ssh alice cat /etc/apt/sources.list) <(ssh bob cat /etc/apt/sources.list)