首先,无论你是在本地还是远程执行此操作,都无论如何都要在打开的会话期间进行
shell访问.如果您只想在远程计算机上执行单个命令并断开连接,则可以在引号内指定它:
原文链接:https://www.f2er.com/centos/373330.htmlssh user@machine 'echo "Who's your Daddy?"'
但是,您几乎没有选项列出特定组中的所有用户:
使用getent工具:
getent group ftp
旧时尚方式:
grep ^ftp /etc/group
使用家庭酿造脚本,您可以根据自己的需要进行调整:
#!/bin/bash srchGroup="$1" # get the corresponding line from /etc/group for thisLine in "`grep "^${srchGroup}:" /etc/group`" do # get the parts of interest grpNumber="`echo ${thisLine} | cut -d":" -f3`" grpUsers="`echo ${thisLine} | cut -d":" -f4 | sed 's/,/ /g'`" done # check /etc/passwd pwdUsers="`awk -F":" '$4 ~ /'${grpNumber}'/ { printf("%s ",$1) }' /etc/passwd`" echo "0 ${srchGroup}" # given at commandline echo "1 ${grpNumber}" # from /etc/group echo "2 ${grpUsers}" # from /etc/group echo "3 ${pwdUsers}" # from /etc/passwd echo "All users: ${grpUsers} ${pwdUsers}"
$./show.group.users ftp 0 ftp 1 500 2 user1 user2 3 homie1 homie2 All users: user1 user2 homie1 homie2