如何使用SSH列出所有FTP用户名

我有一个CentOS 5.5服务器。 如何获得使用SSH的服务器上的所有FTP用户列表?

首先,无论您是在本地还是远程执行此操作,因为无论如何您都可以在打开的会话中访问shell。 如果您只想在远程计算机上执行单个命令并断开连接,则可以在引号内指定它:

ssh user@machine 'echo "Who's your Daddy?"' 

尽pipe如此,你没有办法列出特定组中的所有用户:

使用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 

这个脚本已经从这里撕下来了 。

在centos5中,您可能正在使用vsftpd。 请参阅命令查看vsftpd中的login用户?