代发新闻稿的网站,环球资源网是卖什么的,宿迁手机网站开发公司,中国制造网外贸你为什么不写自己的login-shell#xff1f; 为此使用Bash会非常简单#xff0c;但您可以使用任何语言。Bash中的示例使用您喜欢的编辑器创建文件;(这可以是任何名称或路径#xff0c;但应该是和)#xff1a;#!/bin/bashcommands(man pwd 为此使用Bash会非常简单但您可以使用任何语言。Bash中的示例使用您喜欢的编辑器创建文件;(这可以是任何名称或路径但应该是和)#!/bin/bashcommands(man pwd ls whoami)timestamp(){ date %Y-%m-%s %H:%M:%S; }log(){ echo -e $(timestamp)\t$1\t$(whoami)\t$2 /var/log/rbash.log; }trycmd(){# Provide an option to exit the shellif [[ $ln exit ]] || [[ $ln q ]]thenexit# You can do exact string matching for some alias:elif [[ $ln help ]]thenecho Type exit or q to quit.echo Commands you can use:echo helpecho echoecho ${commands[]} | tr \n | awk {print $0}# You can use custom regular expression matching:elif [[ $ln ~ ^echo\ .*$ ]]thenln${ln:5}echo $ln # Beware, these double quotes are important to prevent malicious injection# For example, optionally you can log this commandlog COMMAND echo $ln# Or you could even check an array of commands:elseokfalsefor cmd in ${commands[]}doif [[ $cmd $ln ]]thenoktruefidoneif $okthen$lnelselog DENIED $cmdfifi}# Optionally show a friendly welcome-message with instructions since it is a custom shellecho $(timestamp) Welcome, $(whoami). Type help for information.# Optionally log the loginlog LOGIN $# Optionally log the logouttrap trap\\;log LOGOUT;exit EXIT# Optionally check for -c custom_command arguments passed directly to shell# Then you can also use ssh userhost custom_command, which will execute /root/rbash.shif [[ $1 -c ]]thenshifttrycmd $elsewhile echo -n read lndotrycmd $lndonefi您所要做的就是将此可执行文件设置为登录shell。 例如编辑;文件并将该用户的当前登录shell替换为。这只是一个简单的例子但您可以根据需要将其设置为高级这个想法就在那里。 小心不要通过更改自己和唯一用户的登录shell来锁定自己。 并始终测试奇怪的符号和命令看它是否真的安全。你可以用以下方法测试它;。注意确保匹配整个命令并注意通配符 最好排除Bash符号如;,,,||,$并确认反引号。根据您给用户的自由度它不会比这更安全。 我发现通常我只需要让一个只能访问少量相关命令的用户在这种情况下这确实是更好的解决方案。但是您是否希望提供更多自由监狱和权限可能更合适。 很容易犯错误只有在已经太晚的时候才会注意到。