Tuesday, June 25, 2013

Reversing SVN using good revision number

When updating the codes or code only using svn, below usually is the output:

-bash-3.2$ svn update --force
svn.user@192.168.1.1's password:
U    code01.php
Updated to revision 15701.








but if the dev team wants to revert that to previous revision because there was an error on the code, then the possible command is below:

say, the good revision is 15690 as per dev.


-bash-3.2$ svn merge -r HEAD:15690 code01.php
svn.user@192.168.1.1's password:
--- Reverse-merging r15701 through r15691 into 'code01.php':
U    code01.php











Now reverted back to a good revision.

Thursday, June 20, 2013

Monitoring a directory for new file, deleted file, modified file with inotifywait and send thru email

On my setup, I am using CentOS

Add epel repo

yum install inotify-tools

create a bash script at /usr/ocal/bin/inotify_daemon.sh with entry below:

#!/bin/bash
pgrep inotifywait > /dev/null
if [ $? -eq 0 ]
then
exit
else
inotifywait --format '%w%f %e %T' --timefmt '%Y/%m/%d-%H:%M:%S' -e create,delete,modify,move -mrq /path/to/folder/ |while read file;do echo $file | mail -s "activity alert" myuser@mydomain.com; done &
fi

then create a cron entry at crontab or root cron.

* * * * * /usr/ocal/bin/inotify_daemon.sh

The cron will run and if  inotify_daemon.sh get accidentally killed, it will run it again. If already running, then it will exit. 

I assume that the server has a working smtp and tested to relay email to a ligit and working email system.

Sample email body once it will work is below:

/path/to/folder/test2 DELETE,ISDIR 2013/06/20-05:11:09

the notification that the folder has been deleted.



Tuesday, June 18, 2013

chroot sftp

Please update the openssl-server at least
openssh-server-5-xx or
openssh-server-6-xx

CentOS 6.3 has openssh-server-5-xx already.

Ok, assuming that above version has been aquired.

below are my process.. some process are based on results if you google sftp + chroot, just make my self a note to remember.

I am creating a user.sftp user account and sftpusers group as sample.

 
1. create a group named sftpusers -- groupadd sftpusers
2. mkdir /ftp/sftpusers ---------> this will be my users root home directory.
3. add a user to be used for sftp
useradd -g sftpusers -d /ftp/sftpusers/user.sftp -s /sbin/nologin user.sftp
4. edit the file /etc/ssh/sshd_config

comment out the line that contains:

Subsystem sftp /usr/libexec/openssh/sftp-server

and replaced with:

#----
#Subsystem sftp /usr/libexec/openssh/sftp-server
Subsystem sftp internal-sftp
#----

then append the Match Group entry.

#----
Match Group sftpusers
ChrootDirectory /ftp/sftpusers/%u
ForceCommand internal-sftp
#----

5. create a folder inside /ftp/sftpusers/user.sftp/ and name it anything, here, I named it upload_dir

mkdir /ftp/sftpusers/user.sftp/upload_dir

6. ownership

chown root /ftp/sftpusers/user.sftp
chmod go-w /ftp/sftpusers/user.sftp
chown user.sftp:sftpusers /ftp/sftpusers/user.sftp/upload_dir
chmod u+rwX /ftp/sftpusers/user.sftp
chmod g+rx /ftp/sftpusers/user.sftp

check the owner, should be

drwxr-xr-x. 3 root sftpusers 4096 Jun 17 21:45 user.sftp

7. restart sshd service

when user is able to login via sftp client, if he tries to travserve to other dir..
error will be like below.

ftp> cd /etc/
Couldn't canonicalise: No such file or directory
sftp> ls