4

I have a CentOS 5.5 server. How can I get a list of all the FTP users on the server using SSH?

1
  • what FTP server do you have installed?
    – Feiticeir0
    Jun 30, 2011 at 18:26

2 Answers 2

9

First of all, there is no matter if you're doing this locally or remotely, since you will have shell access during the opened session anyway. If you want to just execute a single command on the remote machine and disconnect, you can specify it within quotes:

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

Nevertheless, you have few options to list all users within specific group:

Using getent tool:

getent group ftp

Old-fashion way:

grep ^ftp /etc/group

Using a home-brew script, which you can adapt to your own needs:

#!/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

This script been ripped from here.

0

In centos5, you're probably using vsftpd. See Command to view logged on users in vsftpd?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .