Sunday, 31 March 2013

Restrict users access to only their home directory in vsftp

If you want to restrict FTP users to have access only their home directory but not outside of their own directory. You have to setup chroot.

1. open vsftpd configuration file
vi /etc/vsftpd/vsftpd.conf

2. Uncomment the below line
$ chroot_local_user=YES

3. Save and close the file. Restart vsftpd.
$ /etc/init.d/vsftpd restart

As a result FTP users can't access directories other than their home.

ftp> cd /home
550 Failed to change directory.

Thats it.

Friday, 29 March 2013

copy/move/delete files using xargs


How to move/copy/delete largest 15 files to a particular directory

Go to the user directory
$ cd /home/user

If you want to move them, use this below command
$ ls -s|sort -n|tail -15|awk '{print $2}'|while read f;do mv "$f" /backup;done


Explanation:
ls -s - prints size of each file
sort -n - sort files
tail -15 - 15 largest files
awk '{print $2}' - cut the filename
while loop moves files to /backup directory




If you want to delete them, use this below command
$ ls -s|sort -n|tail -15|awk '{print $2}'|while read f;do rm "$f";done

If you want to copy them, use this below command
$ ls -s|sort -n|tail -15|awk '{print $2}'|while read f;do cp "$f" /backup;done


Fix files and folder permission on linux


For files:
find . -type f -exec chmod 644 {} \;

For dirs:

find . -type d -exec chmod 755 {} \;

Monday, 25 March 2013

wget recursive download using ftp


wget recursive download using ftp 

$ wget -r ftp://username:password@ip.of.old.host

If you get error like:

$ wget -r ftp://ftp:M8cf#5GP@xx.xx.xx.xx
  ftp://ftp//:M8cf#5GP@xx.xx.xx.xx: Bad port number.

however if you remove special characters like #,$ and ? from the password than the same will work fine.


wget recursive ftp with mirroring option

wget -m ftp://username:Password@ftp.example.com


Saturday, 23 March 2013

assign multiple shared IPs in WHM


You can add more shared IPs by following the steps shown below.
cd /var/cpanel/mainips

If there is no such directory, create it.

mkdir -p /var/cpanel/mainips

vi /var/cpanel/mainips/root

Add the current main shared IP and the secondary ip.


cat /var/cpanel/mainips/root
11.22.33.44
44.33.22.11

Go to WHM » IP Functions » Show/Edit Reserved IPs


You can see the status of new IPs as 'Main/shared IP for root'.

That's it :)