Cookbook for adding a restricted FTP user

Note: A user will not have the ability to travel anywhere outside the home directory on the system.  Setting up a bogus shell with exit 0 as the contents will cause the connection of a user to be immediately terminated if the user attempts to telnet into the system.

1. Configure the ftpaccess file (if needed, recommend using ftponly group):

a. cd /etc/ftpd

b. cp -p /usr/newconfig/etc/ftpd/ftpaccess .

c. vi ftpaccess.  At the bottom of the file there is a guestgroup

directive ‘guestgroup ftponly’.

i. Either change that group designation to one you already

have or keep that designation.

ii. If you are keeping the ftponly group, then create that

group on your system.

2. Modify the /etc/inetd.conf file to enable the use of the ftpaccess

file (may already be present).

a. vi /etc/inetd.conf

b. Add the -a flag to the ftp daemon:

ftp  stream tcp nowait root /usr/lbin/ftpd    ftpd -a -l

d. inetd -c

4. Create a bogus shell for users that will only have FTP access to

the system:

a. echo “#/usr/bin/shnexit 0” > /usr/bin/ftpshell

c. chmod 555 /usr/bin/ftpshell

d. chown bin:bin /usr/bin/ftpshell

5. Create the /etc/shells file:

a. vi /etc/shells

Put these lines in the file:

/sbin/sh

/usr/bin/ksh

/usr/bin/sh

/usr/bin/csh

/usr/bin/rsh

/usr/bin/rksh

/usr/bin/keysh

/bin/sh

/bin/ksh

/bin/csh

/bin/rsh

/bin/rksh

/usr/bin/ftpshell

6. Now add a user to the system.  Use a group that is ‘ftponly’ and make the user’s shell /usr/bin/ftpshell.

7. Use SAM to limit the user to his home directory by setting up the HOME directory in this form:

/home/username/./

Note: The /./ is the important key here.  When the ftpd verifies a user’s login, it checks and sees that the user is a member of the ‘guestgroup’ ftponly.  It then examines the home directory and, if it sees a /./ in the path, it will then perform a chroot to that directory.  Therefore, when that user FTPs into the system, their home directory will appear as the / directory with no possibility to go up higher.

8. Provide the user with an ls command for ftp:

a. cd /home/username

b. mkdir usr

c. mkdir usr/bin

d. cp -p /sbin/ls usr/bin

e. chown -R bin:bin usr

f. chmod -R 555 usr

– See more at: http://serviceitdirect.com/blog/cookbook-adding-restricted-ftp-user#sthash.rByZh5vZ.dpuf


Tags: