最近在logstash中使用nobody用戶啟動logstash,一想,nobody用戶的shell不是/sbin/nologin嗎? 不能登錄執行命令呀?
於是看了一下它的啟動腳本,是使用其他方式進行的。。。
玩了幾年linux竟然還不知道chroot可以干這事,只知道chroot將根目錄切換到某一位置,,汗顏。。
使用su -l nobody -c "命令"方式
然,nobody用戶的shell是/sbin/nologin,執行命令失敗
# su -l nobody -c "/usr/bin/ls /tmp" This account is currently not available.
那runuser呢? 同樣不行。。。
# runuser -c "ls /tmp" nobody This account is currently not available.
最后使用chroot是可以的。。
# chroot --userspec=99:99 / sh -c id uid=99(nobody) gid=99(nobody) 組=99(nobody),0(root)
知識貴在積累。
chroot命令幫助
# chroot --help 用法:chroot [選項] 新根 [命令 [參數]...] 或:chroot 選項 以指定的新根為運行指定命令時的的根目錄。 --userspec=用戶:組 指定所用的用戶及用戶組(可使用"數字"或"名字") --groups=組列表 指定可供選擇的用戶組列表,形如組1,組2,組3... --help 顯示此幫助信息並退出 --version 顯示版本信息並退出 If no command is given, run '${SHELL} -i' (default: '/bin/sh -i'). GNU coreutils online help: <http://www.gnu.org/software/coreutils/> 請向<http://translationproject.org/team/zh_CN.html> 報告chroot 的翻譯錯誤 要獲取完整文檔,請運行:info coreutils 'chroot invocation'