NcFtpd中用自带数据库工具添加虚拟用户
分类:服务器端技术 作者: 秋天 时间: 18-08-2005
NcFtpd是Linux下少数几个及其出色的ftpd之一的ncftpd.
其自身带有一个添加虚拟用户的工具,可以用来添加虚拟的非系统FTP用户,ncftpd_passwd用法说明如下:
Ncftpd密码数据库文件路径:(来自general.cf文件设置)
passwd=/usr/local/etc/ncftpd/pwdb/passwd.db
增加新用户:
To add a user, run the program specifying the database file with the -f flag, and the complete user record specified by the -a flag. Since the user record may have whitespace in it, use your shell’s quote characters appropriately.
Example 1: Add the mgleason user above, into a database named /usr/local/etc/ncftpd/pwdb/passwd.db.
root# ncftpd_passwd -f /usr/local/etc/ncftpd/pwdb/passwd.db -a “mgleason:75hv0xCjznz1U:500:600,700,701,702:Mike Gleason:/home/mgleason:/bin/ksh”
It is inconvenient to use some other program to create the encrypted password based off of the cleartext password, so you can use the -c flag to tell the utility to encrypt the contents of the password field for you before adding the record.
Example 2: Add the mgleason user above, setting the password to secret.
root# ncftpd_passwd -f /us…/passwd.db -c -a “mgleason:secret:500:600,700,701,702:Mike Gleason:/home/mgleason:/bin/ksh”
If you want to create a user whose user ID is identical to an existing user in the /etc/passwd file, you may use that user’s name instead of manually look up the user ID. Similarly, you may substitute group names for group IDs and the utility will look them up for you.
Example 3: Add the mgleason user above, with user and group name replacement.
root# ncftpd_passwd -f /us…/passwd.db -a “mgleason:75hv0xCjznz1U:mikegl:users,admin,dev,ops:Mike Gleason:/home/mgleason:/bin/ksh”
更改用户:
Modifying a user entry is the same as adding a new one, except you need to use the update flag (-u), instead of the add flag (-a).
Example: Change the password for mgleason to myxlplxx (using the -c flag also).
root# ncftpd_passwd -f /us…/passwd.db -c -u “mgleason:myxlplxx:mikegl:users,admin,dev,ops:Mike Gleason:/home/mgleason:/bin/ksh”
更改用户密码:
While the update flag lets you change an entire record, often all that is desired is to change the password field of the record. You can do this by using the -p flag to specify a user record, and then ncftpd_passwd will prompt you for a new password. You can also use the -P flag to specify the encrypted password directly, if you happen to have it.
This flag can also be used by a non-superuser to change their own password entry. This requires some special setup, as described in the section on advanced options below.
Example 1: Change the password for mgleason to myxlplxx
root# ncftpd_passwd -f /usr/local/etc/ncftpd/pwdb/passwd.db -p mgleason
New password for mgleason:
Verify password for mgleason:
Password changed for user mgleason.
Example 2: Change the encrypted password for mgleason:
root# ncftpd_passwd -f /us…/passwd.db -p mgleason -P ‘d.Ts7N8a3ozbQ’
查询用户:
To print the record for a user, specify the user name with the -Q flag along with the database.
Example: Query mgleason’s record.
root# ncftpd_passwd -f /usr/local/etc/ncftpd/pwdb/passwd.db -Q mgleason
User: mgleason
Encrypted password: 75hv0xCjznz1U
UID: 500
GID: 600
Supplementary GIDs: 700, 701, 702
GECOS: Mike Gleason
Home directory: /home/mgleason
Shell: /bin/ksh
删除用户:
Deleting users
To remove a user’s record, specify the user name with the -d flag along with the database.
Example: Delete mgleason’s record.
root# ncftpd_passwd -f /usr/local/etc/ncftpd/pwdb/passwd.db -d mgleason
列出所有用户列表:
You may use the export flag (-x) to convert a database into a textual format.
Example: Dump the entire passwd.db database.
root# ncftpd_passwd -f /usr/local/etc/ncftpd/pwdb.db -x
pgleason:ldDbXYr308x.w:502:600,700:Patrick Gleason:/home/pgleason:/bin/tcsh
jgleason:OvHSMCPLgL6bA:501:600:Jimmy Gleason:/home/jgleason:/bin/bash
mgleason:75hv0xCjznz1U:500:600,700,701,702:Mike Gleason:/home/mgleason:/bin/ksh
最后的查询用户以及列出所有用户的两个功能是十分有用的,特别是在Linux这种及其不人性化的系统来说。
如果你有兴趣研究那个passwd.db文件,打开看看,是以二进制来编码的,按照作者的说法。二进制编码不仅能提高安全性,并且可以index的访问任意用户,并跳过那些无用的信息,不想Linux自身的passwd中是明文格式,明文格式必须有序的来访问,ignore那些没用信息的时候,造成了时间的延迟,这也就是为什么很多Linux的初级ftpd在login的时候会反应很迟钝的原因了。NcFtpd用这种方式很有效的解决了这个问题。
NcFtpd还有很多其他优秀的功能以及插件等等,以后有机会我会慢慢介绍。