Wednesday, February 27, 2013

Copy Directory Structure without Files in Linux

If you want to copy the directory structure without any files, you can use following command.
rsync -av --include '*/' --exclude '*' /path/source/dir /path/destination/dir
'rsync' gives you utility to copy directory with files or without files.

If you want to copy the directory structure without any files from one host to another. You can use
rsync -av --include '*/' --exclude '*' /path/source/dir user@host:/path/destination/dir
Examples:
Suppose I want to copy the directory structure of /etc in /root/tmp on same host.
rsync -av --include '*/' --exclude '*' /etc /root/tmp
It will copy all directories of /etc in the /root/tmp without any files.
It will not create directory etc in the /root/tmp. It will start from sub-directories of etc.

Saturday, February 23, 2013

Compile & Run C Program on Linux Terminal



1) Write any C program in text editor and save as filename.c
In following example, I have saved this file on my Desktop.

2) To run this program, you have to compile it first.
$ gcc -o compiled-filename /home/user/Desktop/filename.c 
Where compiled-filename is the name of compiled file, it can be anything.
This will generate a compile copy of your program as a name compiled-filename in same directory where you ran the above command.

3) Now create output copy of your program.
Following command generate a output file of your program in same directory.
$ gcc /home/user/Desktop/filename.c
4) Now run your program.
$ ./a.out 
 or 
$ ./compiled-filename
where a.out is output copy of your program.
Alternatively you can run compiled copy of your program.

Friday, February 22, 2013

Make FTP server secure on Linux : RHEL, CentOS, UBUNTU

To install FTP on Linux Server, click here

1) Open vsftpd.conf (/etc/vsftpd.conf or/etc/vsftpd/vsftpd.conf)
To prevent anonymous log-in, Set anonymous_enable=NO
 In vsftpd.conf, if anonymous_enable=YES, There is no need to put username & password. If you put only hostname and try to log-in, you can log-in. This situation is very dangerous.
For security purpose, Always set this attribute NO. 

2) These are the harmful content for your vsftpd.
If your vsftpd file (/etc/pam.d/vsftpd) has following content, it will allow blank or wrong password. It is a threat for your security.
auth sufficient /lib/security/pam_pwdfile.so pwdfile /home/ftp/passwd
auth required pam_shells.so
account required pam_permit.so
Never make auth sufficient , it should be required always.

Never leave your vsftpd file with above content.

3) Never allow blank or wrong password for ftp user 
Make Sure your vsftpd file has following content

If it is Debian, Ubuntu
auth required pam_listfile.so item=user sense=deny file=/etc/ftpusers onerr=succeed
@include common-account
@include common-session
@include common-auth
auth required pam_shells.so

If it is CentOS, RHEL
session    optional     pam_keyinit.so    force revoke auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed auth       required pam_shells.so auth include password-auth session include password-auth session    required     pam_loginuid.so account include password-auth

4) When you make any changes in the file vsftpd.conf, make sure you have restarted the vsftpd.