允许FTP用户登录并禁止Shell登录的方法

最近安装了vsftpd做FTP服务,发现系统用户的登录shell设置为/sbin/nologin,就无法使用FTP服务。网上资料说,vsftpd会为每个FTP登录用户去在/etc/shells中检查对应的登录shell,因此需要增加一行/sbin/nologin。但是我/etc/shells文件明明有/sbin/nologin。

[plain] view plain copy
  1. [root@localhost ~]# vsftpd -v
  2. vsftpd: version 2.2.2
  3. [root@localhost ~]# cat /etc/shells
  4. /bin/sh
  5. /bin/bash
  6. /sbin/nologin
  7. /bin/tcsh
  8. /bin/csh

但是用户设置/sbin/nologin后,就登录不了,报错如下

[plain] view plain copy
  1. 500 OOPS: cannot change directory:/home/xxx
  2. 500 OOPS: priv_sock_get_cmd
  3. 远程主机关闭连接。

于是看看vsftpd产生的ftp用户的配置,也是/sbin/nologin,为什么他能登录呢?(我允许匿名用户登录),如下

[plain] view plain copy
  1. [root@localhost ~]# cat /etc/passwd | grep ftp
  2. ftp:x:14:50:FTP User:/var/ftp/pub/:/sbin/nologin

发现唯一区别就是指定的主目录不一样,于是我把该用户的主目录/home/xxx换成/var/ftp/pub/,果然可以成功登录了!

参考资料:

1、http://www.linuxidc.com/Linux/2008-06/13712.htm


上一篇:css 内联元素inline 行框全解


下一篇:小妖精的完美游戏教室——人工智能,A*算法,启发因子篇