今天应客户需求需在几台linux系统的服务器上创建一普通用户,并将此用户限制在某一目录之下,但同时又不干扰其他用户的正常使用。看到要求我脑海中闪出的是:创建ftp用户倒是弄过,这类的add用户还真没做过呢。。。刚好来研究研究吧(查资料,并虚拟机实验)。。。了解到了chroot的原理和使用,以下是大致的操作步骤:

        1、首先useradd创建test用户:useradd test

               修改账号密码:passwd test

        2、创建用户的默认根目录:

               mkdir /home/test_root

               cd /home/test_root

               mkdir home

               mkdir etc

               mkdir bin

               mkdir lib

               mkdir user

        3、将需要用到的命令cp至test用户限定的根目录下的相应目录下去:

               cp /bin/* /home/test_root/bin

               cp /etc/* /home/test_root/etc

               cp /lib/* /home/test_root/lib

        4、建立/home/test_root/etc/passwd,内容为/etc/passwd里面test那一行。只要那一行:

               tail -1 /etc/passwd > /home/test_root/etc/passwd

        5、修改/etc/pam.d/ssh 加一句:

               session required pam_chroot.so

        6、修改/etc/security/chroot.conf 添加:

               test /home/test_root

ok,至此一满足需求的账号已经创建好啦。现用test账号登陆系统就只能在其规定的目录下活动喽。。