[iyunv@localhost ~]# useradd user1
[iyunv@localhost ~]# passwd user1
Changing password for user user1.
New password:
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully
#一定要给账号设置密码
2、创建活动目录:
[iyunv@localhost ~]# mkdir /vm/user1 -p
3、进入目录,创建需要的目录:
1
2
3
4
5
6
7
8
9
[iyunv@localhost ~]# cd /vm/user1/
[iyunv@localhost user1]# mkdir bin dev etc lib64 proc dev/pts -p
[iyunv@localhost user1]# ll
total 20
drwxr-xr-x 2 root root 4096 Nov 23 01:33 bin
drwxr-xr-x 3 root root 4096 Nov 23 01:33 dev
drwxr-xr-x 2 root root 4096 Nov 23 01:33 etc
drwxr-xr-x 2 root root 4096 Nov 23 01:33 lib64
drwxr-xr-x 2 root root 4096 Nov 23 01:33 proc
4、拷贝需要的文件和库文件
1
2
3
4
5
6
7
#拷贝lib库文件:
[iyunv@localhost user1]# pwd
/vm/user1
[iyunv@localhost user1]# cp -a /lib64/* lib64/
5、修改/etc/pam.d/sshd
[iyunv@localhost user1]# vim /etc/pam.d/sshd添加:session required pam_chroot.so
6、修改/etc/security/chroot.conf
[iyunv@localhost user1]# vim /etc/security/chroot.conf添加:user1 /vm/user1
7、重启sshd
[iyunv@localhost user1]# /etc/init.d/sshd restartStopping sshd: [ OK ]Starting sshd: [ OK ]
8、测试:
1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@localhost ~]# ssh user1@localhost
user1@localhost's password:
Could not chdir to home directory /home/user1: No such file or directory
-bash-4.1$ ls
bin dev etc lib64 proc
-bash-4.1$ ps
-bash: ps: command not found
-bash-4.1$ pwd
/
-bash-4.1$ cd /
-bash-4.1$ ls
bin dev etc lib64 proc
-bash-4.1$
9、注意:
以上方法只能使用原系统中/bin/目录下的命令
对于/usr/bin/目录下的命令目前还有问题,无法使用
如:ssh命令,ssh命令需要用到/usr/lib64/目录下的相应的库文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#使用以下脚本可以实现将命令依赖的/usr/lib64/下的库文件拷贝到活动目录的lib64/目录下
[iyunv@localhost lib64]# vim abc.sh
#!/bin/bash
cmd="ssh"
cd /vm/user1/lib64
for i in $cmd
do
ldd `which $i` |grep "/usr/lib64/"|sed 's/(.*//g'|awk '{print $NF}'|while read j
do
\cp -a $j ./
if [ `file $j | grep -c symbolic` -eq 1 ];then
sourceFile=`ls -l $j |awk '{print $NF}'`
\cp -a `dirname $j`/$sourceFile ./
fi
done
done