Ubuntu下安裝proFTPd
Ubuntu9.10安裝proFTPd支持SFTP
目的
1)支持SFTP協(xié)議
2)不采用系統(tǒng)帳號(hào)驗(yàn)證方式,改為數(shù)據(jù)庫(kù)MySQL驗(yàn)證
3)數(shù)據(jù)庫(kù)中不保存密碼,只保存經(jīng)過(guò)sha256算法加密過(guò)的可打印16位小寫(xiě)字符串,系統(tǒng)中還需保存一個(gè)salt文件
4)數(shù)據(jù)庫(kù)中指定用戶目錄,proFTPd能夠動(dòng)態(tài)創(chuàng)建用戶目錄
修改ssh服務(wù)端口號(hào)為21
修改文件中的配置/etc/ssh/sshd_config
然后重新啟動(dòng)ssh服務(wù)
sudo /etc/init.d/ssh restart
這不會(huì)影響ssh的使用,客戶端需要用-p參數(shù)指明端口號(hào)
創(chuàng)建ftp系統(tǒng)帳號(hào)
- sudo groupadd ftp
- sudo useradd -u 1005 -s /bin/false -d /bin/null -c "proftpd user" -g ftp ftpuser
- sudo passwd ftp
依賴庫(kù)
確保UBuntu系統(tǒng)中已經(jīng)有/usr/include/mysql/mysql.h和/usr/lib/libmysqlclient.a
獲得源代碼編譯安裝
注意,系統(tǒng)中不能存在其他占用22端口的程序。
- cd /usr/src
- sudo wget ftp://ftp.proftpd.org/distrib/source/proftpd-1.3.3rc3.tar.gz
- sudo tar xvzf proftpd-1.3.3rc3.tar.gz
- cd proftpd-1.3.3rc3
- install_user=ftp install_group=ftp sudo ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var/run --mandir=/usr/local/man --without-pam --disable-auth-pam --enable-openssl --with-modules=mod_ratio:mod_readme:mod_sftp:mod_sql:mod_sql_passwd:mod_sql_mysql --with-includes=/usr/include/mysql --with-libraries=/usr/lib
- sudo make
- sudo make install
編譯成功后,當(dāng)前目錄和/usr/sbin/下都有proftpd程序。
修改配置
修改配置文件/etc/proftd.conf文件,在文件開(kāi)頭添加如下配置
- ServerName "ProFTPD Default Installation"
- ServerType standalone
- DefaultServer on
- RootLogin off
- RequireValidShell off
- DefaultRoot ~
- IdentLookups off
- UseReverseDns off
- CreateHome on
- SQLPasswordEngine on
- SQLPasswordEncoding hex
- SQLPasswordSaltFile /home/chenshu/salt
- # Other mod_sql configuration here
- SQLBackend mysql
- SQLAuthTypes SHA256
- SQLAuthenticate users*
- SQLConnectInfo databaseName @IP :3306 username password 30
- SQLDefaultUID 1003
- SQLDefaultGID 1005
- SQLUserInfo users login password_hash NULL NULL homedir NULL
- SFTPEngine on
- SFTPLog /etc/sftp.log
- SFTPAuthMethods password
- # Host keys, for server host authentication
- SFTPHostKey /etc/ssh/ssh_host_rsa_key
- SFTPHostKey /etc/ssh/ssh_host_dsa_key
# Port 21 is the standard FTP port.
Port 22
創(chuàng)建數(shù)據(jù)表
- CREATE TABLE `users` (
- `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
- `login` varchar(16) NOT NULL,
- `password_hash` varchar(80) NOT NULL,
- `homedir` varchar(1024) NOT NULL,
- PRIMARY KEY (`id`)
- )
制造數(shù)據(jù):
下面是Ruby代碼:
require 'digest/sha2'
puts Digest::SHA256.hexdigest("770328" + "7wjCeqX/")
"770328"是用戶密碼
"7wjCeqX/"是salt,也應(yīng)該保存在/home/chenshu/salt文件中。請(qǐng)不要在文件中添加換行符。
算出的字符串,保存到password_hash列中。
homedir字段保存用戶目錄,如果第一次登錄時(shí)沒(méi)有,會(huì)自動(dòng)創(chuàng)建。
最后啟動(dòng)服務(wù):
- chenshu@chenshu-desktop:/usr/sbin$ sudo ./proftpd
測(cè)試,通過(guò)。這樣就完成了Ubuntu9.10下proFTPd的安裝。
【編輯推薦】