Trying to understand linux script [closed]

I have this Linux script I found and I’m trying to understand it. Could someone please help me to understand it.

The script

if [ ! -d "/home/ftp/$PAM_USER" ]; then
  /bin/su - ftp -s /bin/sh -c "/usr/bin/env mkdir /home/ftp/$PAM_USER"
  /bin/su - ftp -s /bin/sh -c "/usr/bin/env chmod 751 /home/ftp/$PAM_USER"
fi

Things I don’t understand

if [ ! -d "/home/vsftpd/$PAM_USER" ]; then 

I’m assuming the script above is a condition check to see if the pam user directory exist

what does the /bin/su mean

what does the ftp mean

What does -s /bin/sh mean

What does the -c /usr/bin/env mean

  /bin/su - ftp -s /bin/sh -c "/usr/bin/env chmod 751 /home/vsftpd/$PAM_USER"

fi

Lastly how can I test to be sure this script is even working?

I apologize if the answer seems basic or incomplete. Unfortunately do to my current knowledge level, I’m not sure what questions to be asking.

Answer

 /bin/su - ftp -s /bin/sh -c "/usr/bin/env mkdir /home/ftp/$PAM_USER"

Means run the following command

 /usr/bin/env mkdir /home/ftp/$PAM_USER

As the ftp user. You’d need to be root to run the command.

/bin/su will change to a new user ftp and that user is running the command via -c using a /bin/sh shell as referenced by -s

Attribution
Source : Link , Question Author : George , Answer Author : Mike

Leave a Comment