试图在Centos7上使用jailkit。我通过源代码安装了RPM,并在http://dries.eu/rpms/jailkit/jailkit上使用了RPM,并得到了相同的结果。我主要关注的是https://olivier.sessink.nl/jailkit/howtos_色色_shell.html,然而,我也看过许多其他文档。
第一步:创建监狱。我还应该包括jk_lsh吗?稍后再谈这个。而且,这也不是什么大不了的事,但是您建议使用-k选项来创建链接而不是复制链接吗?注意,不存在多个文件。
[root@mybox ~]# jk_init -v -j /home/jail basicshell editors extendedshell netutils ssh sftp scp | grep 'do not exist'
Source file(s) /lib/libnsl.so.1 do not exist
Source file(s) /lib/libnss*.so.2 do not exist
Source file(s) /etc/bash.bashrc do not exist
Source file(s) /usr/lib/locale/en_US.utf8 do not exist
Source file(s) /etc/vimrc do not exist
Source file(s) /etc/joe do not exist
Source file(s) /etc/bash.bashrc do not exist
Source file(s) /usr/lib/locale/en_US.utf8 do not exist
Source file(s) /usr/share/mc do not exist
Source file(s) /etc/vimrc do not exist
Source file(s) /etc/joe do not exist
Source file(s) /lib/libnss_dns.so.2 do not exist
Source file(s) /usr/lib/sftp-server do not exist
Source file(s) /usr/lib/misc/sftp-server do not exist
Source file(s) /usr/libexec/sftp-server do not exist
Source file(s) /usr/lib/openssh/sftp-server do not exist
Source file(s) /usr/lib/sftp-server do not exist
Source file(s) /usr/lib/misc/sftp-server do not exist
Source file(s) /usr/libexec/sftp-server do not exist
Source file(s) /usr/lib/openssh/sftp-server do not exist
[root@mybox ~]#步骤2:将用户添加到监狱中。不能添加用户,因为没有添加/usr/sbin/jk_lsh。我可以使用jk_init添加它,也可以使用-s /bin/bash为用户指定shell (这似乎是以后需要修改的)。我都试过了。
[root@mybox ~]# jk_jailuser -m -v -j /home/jail testuser1
invalid shell, /home/jail/usr/sbin/jk_lsh does not exist
enter jail directory: /home/jail
invalid shell, /home/jail/usr/sbin/jk_lsh does not exist
enter jail directory: ^C
aborted..
[root@mybox ~]#
# add jk_lsh and jail users...
[root@mybox ~]# cat /etc/passwd | grep testuser
testuser1:x:1002:1002::/home/jail/./home/testuser1:/usr/sbin/jk_chrootsh
testuser2:x:1003:1003::/home/jail/./home/testuser2:/usr/sbin/jk_chrootsh
[root@mybox ~]# cat /home/jail/etc/passwd
root:x:0:0:root:/root:/bin/bash
testuser1:x:1002:1002::/home/testuser1:/usr/sbin/jk_lsh
testuser2:x:1003:1003::/home/testuser2:/bin/bash
[root@mybox ~]#步骤3:以新用户身份登录。尝试以testuser1或testuser2身份登录时,外壳立即关闭。
[root@mybox ~]# tail -6 /var/log/secure
Sep 7 14:12:24 mybox sshd[2615]: Accepted password for testuser1 from 11.22.333.444 port 62008 ssh2
Sep 7 14:12:24 mybox sshd[2615]: pam_unix(sshd:session): session opened for user testuser1 by (uid=0)
Sep 7 14:12:24 mybox sshd[2615]: pam_unix(sshd:session): session closed for user testuser1
Sep 7 14:12:36 mybox sshd[2623]: Accepted password for testuser2 from 11.22.333.444 port 62009 ssh2
Sep 7 14:12:36 mybox sshd[2623]: pam_unix(sshd:session): session opened for user testuser2 by (uid=0)
Sep 7 14:12:37 mybox sshd[2623]: pam_unix(sshd:session): session closed for user testuser2
[root@mybox ~]#我的黑客解决方案:当从源代码安装并使用jk_init -k ..时,我在添加用户之前执行jk_cp -v -f -j /home/jail /bin/bash,这样做可以防止shell立即关闭。不知道为什么这是必要的,或者-k标志或需要从源做的改变。无论如何,在我看来,需要做这一步可能是一个糟糕的解决办法。
最后一个小问题:没什么大不了的,但在更新时也会得到这些错误:
[root@mybox ~]# jk_update -j /home/jail -d
ERROR: while scannign dir /home/jail/lib/: No such file or directory
ERROR: while scannign dir /home/jail/opt/: No such file or directory
[root@mybox ~]#我的问题是:对用户进行监禁的正确方法是什么,这样shell就不会立即关闭?
发布于 2017-09-19 09:19:30
你可以试试这个,它很容易使用。
您只需3步就可以将用户设置为监狱。
1. add user to system
2. create a jail with jail-shell command.
3. set user into jail with jail-shell command.下面是工具:https://github.com/pymumu/jail-shell
注意:我是这个工具的开发者,所以这是自我推销。
尼克·彭
https://unix.stackexchange.com/questions/390972
复制相似问题