Difference between sudo -u and su -c

5,309

The tomcat's shell is /bin/false, you can run with su - as

sudo su -s /bin/bash -c "touch temp/b.txt" tomcat
Share:
5,309

Related videos on Youtube

iwekesi
Author by

iwekesi

Updated on September 18, 2022

Comments

  • iwekesi
    iwekesi over 1 year

    The following is being executed from an account with sudo privileges:

    I have a user tomcat created with the following command

    sudo useradd -g tomcat -d /usr/local/tomcat -m -s /bin/false tomcat
    

    I also have a user test created with the following command

    sudo adduser test
    

    I have a folder temp and perms 777 are set on this folder

    chmod 777 temp
    

    Following are my observations:

    ## This works and I can see temp/a.txt being created
    sudo -u tomcat touch temp/a.txt 
    
    ## Does not work. 
    sudo su -c "touch temp/b.txt" tomcat
    
    ## works
    sudo -u test touch temp/c.txt
    
    ## works
    sudo su -c "touch temp/d.txt" test
    

    So my question is what exactly is wrong with tomcat user?