如何在unix上搭建FTP Server

来源:互联网 发布:淘宝投诉电话号码400 编辑:程序博客网 时间:2024/05/09 11:51

非常简单的step by step to build a FTP server:

原文链接:

http://en.wikibooks.org/wiki/Solaris/Solaris_FTP_Server_Setup


  • 首先需要确定机器上是否已经安装了FTP

bash-3.00# svcs | grep ftp
online         Nov_29   svc:/network/ftp:default

如果没有返回则说明没有安装ftp。


  • 安装ftp

solaris自带的FTP是ftpd(ftp daemon),但默认不会安装。我用来安装ftpd的安装包是CMP_RSC_ftp_Sol_1-0-0_install_1.spb

也可以使用其他的FTP工具例如vsftpd(very secure ftp daemon),但是一般ftpd就够了。

注意只能在global zone安装ftpd。在子zone上安装时会报错。一旦在global zone安装完毕,每一个子zone就都可以使用ftp server了。但是需要分别start up 服务。


  • 安装后启动ftp server

1. Login as root

2. Create a new user "ftp" in /etc/passwd file as follows:

ftp:x:123:1:Anonymous FTP:/export/home/ftp:/bin/true

这一步实际是创建一个系统级的用户ftp。在/etc/passwd中直接添加用户,和直接使用useradd命令加用户是一样的。

对于上面这行数据的意思,请自行搜索/etc/passwd的说明。

在这里我们并没有给改账户设置密码。

3. Then we need to sync this file with /etc/shadow with:

pwconv
直接运行上面的命令就好。

4. Create a directory for this ftp account like this:

mkdir /export/home/ftp

Change the ownership on this directory to:

chown -R root:other /export/home/ftp
这步其实是给ftp用户创建一个home目录。

5. Set permissions on just created directory with 555 permission:

chmod 555 /export/home/ftp

6. Create directory pub where the files will be uploaded and downloaded from:

mkdir /export/home/ftp/pub

7. Change permissions on this pub directory to:

chmod 777 /export/home/ftp/pub

8. Modify /etc/ftpd/ftpaccess file by adding the following line:

upload /export/home/ftp /pub yes ftp other 0600 nodirs

9. Now start the ftp server. You will need to su, pfexec, or however you have Solaris setup to run this command

inetadm -e ftp

10. Test to see if the ftp server is running

inetadm | grep ftp

bash-3.00# svcs | grep ftp
online         Nov_29   svc:/network/ftp:default

  • 验证是否可以使用

之后我们可以使用filezilla或其他的ftp client来连接设置好的ftp server。我们可以使用匿名用户连接,密码是任意的电子邮件地址。也可以使用前面设置的ftp账户,没有密码。

或直接运行ftp,如下则说明ftp server正在工作。

bash-3.00# ftp
ftp>


奇怪的是,此时ftp或匿名账户都不能upload文件。同时,也不知道连接的默认目录到底是哪里。

关于匿名用户,在后面有一点说明。


接下来是一篇FTP基础命令的文章,也很简单。

http://www.cs.colostate.edu/helpdocs/ftp.html

其中需要注意的是刚建立好FTP server后,还可以使用一个匿名用户anonymous。你可以直接使用这个匿名账户登录FTP。

Anonymous FTP

At times you may wish to copy files from a remote machine on which you do not have aloginname. This can be done using anonymousFTP.
When the remote machine asks for your login name, you should type in the word anonymous. Instead of apassword, you should enter your own electronic mail address. This allows the remote site to keep records of the anonymous FTP requests.

Once you have been logged in, you are in the anonymous directory for the remote machine. This usually contains a number of public files and directories. Again you should be able to move around in these directories. However,you are only able to copy the files from the remote machine to your own local machine; you are not able to write on the remote machine or to delete any files there.


  • 创建其他ftp用户

此时如果希望创建其他的ftp用户,我们要做的非常简单。

只需要创建系统用户,这个用户就自动可以访问ftp了。而不是和在windows中一样,需要单独在ftp server上创建用户。

和前面一样,直接在/etc/passwd中添加一行:

lillian:x:126:1:account FTP:/files/input/abrun_ps:/bin/ksh

其中/files/input/abrun_ps是默认的用户home目录,需要提前建好这个目录,并且新建的用户对这个目录必须有访问权限。/bin/ksh是用户的默认shell。

因为x表示使用shadow file,所以之后需要运行pwconv。

此时用户已经创建好,但是没有指定密码。


之后在/etc/ftpd/ftpaccess中加入:

upload /export/home/ftp /pub yes portfolio other 0600 nodirs


之后用passwd l + lillian 设置密码。

bash-3.00$ passwd lillian
Enter existing login password:



完成后在putty中用该用户登录unix,看看是否成功。如果成功则使用filezilla连接ftp,可以看到默认的路径就是/files/input/abrun_ps,而且同时有download和upload权限。




原创粉丝点击