How to list all FTP usernames using SSH

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.