我试图设置一个环境,在这个环境中,某个组中的许多用户可以通过SSH连接到服务器,然后使用密钥交换或密码在其上执行一组预定义的命令。 到目前为止,我被告知要查看authorized_keys“命令”部分,但据我所知,这只对非人类用户有用。
有没有办法将某个用户组的许多命令列入黑名单或白名单?
例如,组X中的用户应该能够使用ls ,/ /etc/init.d , rm ,但是没有其他的。
您将需要使用您select的脚本语言创build一个受限命令shell,然后设置sshd以强制使用您指定的组的此受限shell。
例8-1和O'Reilly的SSH的其他部分,Secure Shell第8章展示了如何做前者。
对于后者,请参阅sshd_config(5)的Match指令说明。
例如,您可以将以下内容添加到/etc/ssh/sshd_config :
Match Group X ForceCommand /path/to/your/restricted_shell
我认为正确的做法是将chroot (受控/有限的环境)与ssh结合在一起
你可能想看看这个指南http://www.techrepublic.com/blog/opensource/chroot-users-with-openssh-an-easier-way-to-confine-users-to-their-home-目录/ 229
不知道它适合你的环境与否,我使用这个在我的环境。 这个想法是使用受限制的bash,清理$ PATH,保护$ PATH并将$ PATH设置为$ HOME / bin,然后将所有允许用户运行的二进制文件链接到$ HOME / bin。
------------------------------------------- #!/bin/bash USERS="user" PASS=secret ALLOWED_CMDS="/bin/ping /usr/bin/killall /bin/ps " # creating restricted bash ln -s /bin/bash /bin/rbash for user in ${USERS}; do home=/home/${user} echo useradd --comment \"CDM user with restricted shell\" --home-dir ${home} --shell /bin/rbash ${user} useradd --comment "CDM user with restricted shell" --home-dir ${home} --shell /bin/rbash ${user} echo "set password for ${user}" echo ${PASS} | passwd ${user} --stdin if [ -d ${home} ]; then # deleting unneeded files files=".bashrc .bash_history .bash_logout .bash_profile .emacs .mozilla" for file in ${files}; do rm -rfv ${home}/${file} done # creating bin dir and profile echo "export PATH=\$HOME/bin"> /home/$user/.profile echo "export PS1=\"[\u@\h \W]$ \"">> /home/$user/.profile mkdir ${home}/bin chmod -R 755 ${home} chown -R root:root ${home} chmod 750 ${home}/.profile chown root:${user} ${home}/.profile chmod 2070 /home/$user chown root:$user /home/$user # allowed specific commands only echo "creating symlinks for allowed commands.." for cmd in ${ALLOWED_CMDS}; do ln -sv ${cmd} ${home}/bin/ done fi done ------------------------------------------- [root@puppet tmp]# sh create_user.sh [root@puppet tmp]# su -l user [user@puppet ~]$ ping Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline] [user@puppet ~]$ ls -rbash: ls: command not found [user@puppet ~]$ cd -rbash: cd: restricted [user@puppet ~]$ pwd /home/user [user@puppet ~]$ ps PID TTY TIME CMD 9605 pts/1 00:00:00 rbash 9629 pts/1 00:00:00 ps [user@puppet ~]$ killall Usage: killall [-Z CONTEXT] [-u USER] [ -eIgiqrvw ] [ -SIGNAL ] NAME... [user@puppet ~]$ nc -rbash: nc: command not found [user@puppet ~]$ nmap -rbash: nmap: command not found