How to re-add all system ftp accounts to your /etc/proftpd.passwd file

If for whatever reason, you're missing all or some of your system ftp accounts in your /etc/proftpd.passwd file, you can do the following to ensure they're all present.

First change to the root directory:

cd /root

Then create a file called fix_ftp.sh (use your favorite editor):

nano fix_ftp.sh

Inside this new file in your users directory, insert the following code:

#!/bin/sh

PF=/etc/proftpd.passwd

cd /usr/local/directadmin/data/users
for u in `ls`; do
{
if [ ! -d $u ]; then
continue;
fi

SHADOW=/home/$u/.shadow
if [ ! -e $SHADOW ]; then
continue;
fi

#make sure it doesn't already exist
COUNT=`grep -c -e "^${u}:" $PF`
if [ "$COUNT" -ne 0 ]; then
continue;
fi

UUID=`id -u $u`
UGID=`id -g $u`

echo "${u}:`cat /home/$u/.shadow`:${UUID}:${UGID}:system:/home/${u}:/bin/false";

};
done;

Save/exit, then chmod the script to 755.

chmod 755 fix_ftp.sh



Test it out first (it won't make any changes to your file like this):

./fix_ftp.sh

make sure it's dumping out the information that goes into the proftpd.passwd file.
Once satisfied that it's the data you want, pipe it to the tail end of the file:

./fix_ftp.sh >> /etc/proftpd.passwd

making sure to use 2 > characters (>>)  and not just 1, as using just 1 would delete whatever was previously there (which is a bad thing if there are any ftp@domain.com accounts).

Make sure /etc/proftpd.passwd is chowned to root:ftp as well.

That's it, then just test out the ftp accounts.


Was this article helpful?

mood_bad Dislike 2
mood Like 0
visibility Views: 11130