How to install vsftp on CentOS to create a new user

rpm -qa | grep vsftpd to see if vsftp is installed

Run the command to start the installation

yum -y install vsftpd

centos will automatically download and install.

After installation

Set to run automatically every time you boot

chkconfig vsftpd on

Manual start

service vsftpd start

You can use netstat -tl to see if it is listening on port 21.

Create new user

# useradd –d /var/www -g ftp –s /sbin/nologin myftp

illustrate:

-s /sbin/nologin is to make it unable to log in to the system 
-d is to specify the user directory as /var/www, which can be replaced with any directory you need. 
-g ftp Add the user to the ftp group (vsftp has been created) 
myftp is the ftp user name, replace this myftp with your ftp user name when configuring. 
After executing this command, if the following error message appears: 
useradd: warning: the home directory already exists. 
Not copying any file from skel directory into it. 
This means that the user's directory already exists (/var/www, this can be any file you The set directory), this directory cannot be created again, it is not a failure to add a user, it can be ignored.

Special reminder: If the user created by useradd is not followed by the –s /sbin/nologin parameter, the created user is an ordinary system user who has the permission to log in to the centos server. In a virtual host environment, this is very dangerous. So add the parameter –s /sbin/nologin after the useradd command to add a dedicated ftp account (virtual account) that cannot log in to the system for the centos server virtual host

set password

# passwd myftp 
提示:重复输入2次 
修改/var/www目录属性:(或任何自己定义的目录) 
# chown -R myftp /var/www 递归把所有目录及文件的拥有者设为新添加的ftp用户 
# chmod -R 755 /var/www 递归地设置拥护者全部权限,其他用户只有读取和执行权限 
这样,如果网站运行时需要有写入权限,可以直接通过ftp的用户名来修改。

配置文件 /etc/vsftpd/vsftpd.conf

设置帐户只能访问自己的目录,也就是上面建用户的时候设置的目录–d /var/www 
Chroot_local_user=yes

重启 vsftpd服务

# service vsftpd restart

 

 

 

一、vsftp添加用户

[root@ www.linuxidc.com ~]# adduser -g ftp -s /sbin/nologin mmc

[root@ www.linuxidc.com ~]# passwd mmc

输入密码。

这样添加了一个用户名为:mmc 的新用户,新添加的用户只能登录FTP,不能作为系统用户登录。

新添加的用户默认家目录是在/home 下有个以用户名为文件名的文件夹,如果想使用指定的目录给用户,可以作以下操作:

(adduser 有个参数是:-d, --home-dir HOME_DIR       home directory of the new account)

[root@ www.linuxidc.com ~]# adduser -d /vsftphome/mmc1 -g ftp -s /sbin/nologin mmc1

[root@ www.linuxidc.com ~]# passwd mmc1

输入密码。

完成新建了一个名为mmc1,家目录被指定为/vsftphome/mmc1 的ftp用户。

测试用户。

二、限定FTP用户只能访问自己的家目录,而不能返回上一层目录进入其他目录。

修改配置文件:/etc/vsftpd/vsftpd.conf

[root@ www.linuxidc.com vsftpd]# vi vsftpd.conf

去掉下面两行参数的注释符号(‘#’号)

chroot_list_enable=YES

chroot_list_file=/etc/vsftpd/chroot_list

在/etc/vsftpd下创建chroot_list文件:

[root@ www.linuxidc.com vsftpd]# touch chroot_list

然后加入需要限制的用户名(一行一个),如:

mmc

mmc1

保存退出。

重启服务,测试。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326909242&siteId=291194637