Knowledgebase
How to create a ftp in a linux server but can’t view its root’s directories.
Posted by Maria Cristina Bayno on 02 July 2013 10:11 AM

Sample for this is the dot26!

Note: Create a ftp user to dot26 (linux) and make sure that homeservice's directory can be manage by scribble.

Login via ssh:

check the status of ftp service: 
[root@homeservice www]# /etc/init.d/vsftpd status
vsftpd is stopped
You have new mail in /var/spool/mail/root

start the ftp service:
[root@homeservice www]# /etc/init.d/vsftpd start
Starting vsftpd for vsftpd: [ OK ]
You have new mail in /var/spool/mail/root

check again the status of ftp service:
[root@homeservice www]# /etc/init.d/vsftpd status
vsftpd (pid 1575) is running...

note: if there is no vsftpd installed to the server, just run the ff command:

install vsftpd


Create a ftp account:
[root@homeservice www]# /usr/sbin/groupadd ftpaccounts
You have new mail in /var/spool/mail/root

Create a name "scribble" account:
[root@homeservice www]# /usr/sbin/adduser -g ftpaccounts -d /home/user/ scribble

Make a password for scribble:
[root@homeservice www]# passwd scribble
Changing password for user scribble.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

Change the owner of /home/user:
[root@homeservice www]# chown scribble:ftpaccounts /home/user

Change the permission of /home/user:
[root@homeservice www]# chmod 775 /home/user

Edit /etc/vsftpd/vsftpd.conf file and make sure 'local_enable=YES' is uncommented:
[root@homeservice www]# vi /etc/vsftpd/vsftpd.conf

Restart the ftp service:
[root@homeservice www]# /etc/init.d/vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]
You have new mail in /var/spool/mail/root

Problem: I need to provide him/her access for another folder /home/www/homeservice.

The important one here is:
chroot_local_user=YES

So I added the code to vsftpd.conf: 

[root@homeservice www]# vi /etc/vsftpd/vsftpd.conf
You have new mail in /var/spool/mail/root

Restart the ft service:
[root@homeservice www]# /etc/init.d/vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]

[root@homeservice www]# cd /home/
[root@homeservice home]# cd user/

Take note: Of course that one solution to overcome this limitation is to disable chroot and allow the ftp users full access to all the system files. This is not at all recommended and this little tip will show you how you can achieve this with chroot enabled. The solution to this little problem is to mount the needed directory using the –bind parameter… from the man page of mount: “–bind Remount a subtree somewhere else (so that its contents are available in both places)“.

So we might do something like:
[root@homeservice user]# mkdir /home/user/homeservice
[root@homeservice user]# mount --bind /home/www/homeservice/ /home/user/homeservice

After this the ftp user will be able to see the needed files in his home directory and use them in his ftp client as if they were local files.

If you need to make this configuration permanent you can either add the mount command in some startup script or you can just include a line in /etc/fstab:

/home/www/homeservice/ /home/user/homeservice none bind 0 0

[root@homeservice user]# vi /etc/fstab
You have new mail in /var/spool/mail/root

Restart the ftp service:
[root@homeservice user]# /etc/init.d/vsftpd restart
Shutting down vsftpd: [ OK ]
Starting vsftpd for vsftpd: [ OK ]

Try to check now the contents of newly created directory:
[root@homeservice user]# cd /home/user/
[root@homeservice user]# cd homeservice/
[root@homeservice homeservice]# ls
career_style.css engine index.php php.log rss uploads
contact_us.html.old error.php install phpmyadmin services webjobs_2[1].0.0_base.zip
contact_us.htmlorig FreeContactForm install.php.old resume.php smartway webjobs_2[1].0.0_standard_resume_wizard.zip
contact_us.php hack_ip.zip install_resume_wizard.html resume_wizard_install.php templates wsp_get_captcha.php
css images lib robots.txt update.php

Automatically, the contents or webfiles of homeservice are also there at /home/user/homeservice.

Check the contents of true directory of homeservice.ph:

[root@homeservice homeservice]# cd /home/www/homeservice
[root@homeservice homeservice]# ls
career_style.css engine index.php php.log rss uploads
contact_us.html.old error.php install phpmyadmin services webjobs_2[1].0.0_base.zip
contact_us.htmlorig FreeContactForm install.php.old resume.php smartway webjobs_2[1].0.0_standard_resume_wizard.zip
contact_us.php hack_ip.zip install_resume_wizard.html resume_wizard_install.php templates wsp_get_captcha.php
css images lib robots.txt update.php

Conlcusion: they have the same contents now!!

--cristina
(0 vote(s))
This article was helpful
This article was not helpful

Comments (0)
Post a new comment
 
 
Full Name:
Email:
Comments:
Help Desk Software by Kayako Fusion