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"

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"


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.

  • Have you tried calling these things a piece at a time?
    – wlraider70
    Feb 1, 2015 at 4:34
  • @wlraider707 I've been struggling with this stuff for hours. Unfortunately I don't know how to log any of this to know if it's even working. I'm not even sure if the script is being fired. I'm using pam and I think it should be fired with this line within my pam config auth required pam_script.so onerr=success dir=/etc/pam-script but I'm not sure if it's even working. There is no errors in the logs
    – George
    Feb 1, 2015 at 4:45
  • 4
    I'm voting to close this question as off-topic because the poster needs to study basic unix usage and administration. While I understand the poster's frustration and desire to learn, this isn't the place for it. There are plenty of web sites and books that teach 101-level unix skills. Serverfault is not one of them.
    – Jenny D
    Feb 1, 2015 at 8:19
  • 3
    @George I did not say that the question was bad. I said that this is not the place for it. This is stuff that a unix administrator should know, or know how to find out, before getting root on a server.
    – Jenny D
    Feb 1, 2015 at 9:07
  • 2
    @George It is a QA site with a specific audience. I think maybe you missed reading the help center. Your question is a beginner's question, and this is not a site for beginners. I don't know how to put it more clearly than that. Again, this is not a reflection on you as a person. Saying that "sorry, you're in the wrong room" is not an attack or being rude.
    – Jenny D
    Feb 1, 2015 at 9:26

1 Answer 1

 /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

  • does ftp user have anything to do with the ftp directory in home/ I found the script here t3chnick.blogspot.com/2011/12/… My biggest issue is my directory structure is /home/vsftpd/ and his was /opt/ftp/ My script doesn't appear to be working, but I'm also not sure if there is an issue with pam_script.
    – George
    Feb 1, 2015 at 5:07
  • seems like $PAM_USER is the user you use to ftp in so /home/ftp dir would need to be writable by the ftp user
    – Mike
    Feb 1, 2015 at 5:10
  • I think your starting to put me on the right track. Thanks. So a couple more quick questions if you have the time. He seems to have provided a more complete answer here askubuntu.com/questions/406486/… I'm seeing a guest_username=ftp Would it be fair to assume that user would be the one writing the directory? or do you think I'm wrong?
    – George
    Feb 1, 2015 at 5:15
  • @George Please, please don't just take a script off of the internet and run it unless you have the prerequisite knowledge to know what it does. This is dangerous. If you don't understand the script, how can you know that it doesn't cause a security hole or enable an attack on your server?
    – Jenny D
    Feb 1, 2015 at 9:11
  • @JennyD I do believe this is why I posted my question asking what the script did before using it. Unlike you, Mike was able to provide me with a useful answer that enabled me to dig deep enough to realize this wasn't the way I wanted to go.
    – George
    Feb 1, 2015 at 9:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.