Em primeiro lugar, responderei às perguntas 1 e 3, porque 3 é um caso especial de 1, a pergunta 2 é, na verdade, muito simples, mas vamos sujar as mãos!
Apache -case
Em primeiro lugar, executamos a modificação específica do Apache com o SED e, em seguida, certificamos-nos de que o Apache esteja realmente em execução com o pretendido user:group
que é www-data:web-content
.
# sed -i s@APACHE_RUN_GROUP=www-data@APACHE_RUN_GROUP=web-content@g /etc/apache2/envvars
# /etc/init.d/apache2 restart
# ps -o pid,user,group,fname $(pidof apache2)
PID USER GROUP COMMAND
24514 root root apache2
24521 www-data 1001 apache2
24522 www-data 1001 apache2
24523 www-data 1001 apache2
24524 www-data 1001 apache2
# grep 1001 /etc/group
web-content:x:1001:www-data,xyz,apache
# getent group 1001
web-content:x:1001:www-data,xyz,apache
onde verificamos a correspondência de 1001-placeholder com dois comandos diferentes, com certeza 1001 corresponde a web-content-group. Um processo do Apache deve estar rodando como root:root
porque ele precisa se ligar à porta 80, de acordo com o arquivo. Então agora seu apache está rodando como www-data:web-content
. Você pode agradecer a THE e SO por colaborar com esse quebra-cabeça, seja bem-vindo ao #Debian -channel em Freenode.
Geral -case
There are actually many ways to Rome:
setuid/setgid
- ...
- using the start/stop -daemons in
/etc/init.d
But according to THE, there is no general way of accomplishing this that would work over all platforms. You need to learn to use the right tool at the right spot. For example, the starting point with Apache -case was to investigate the
/etc/apache2/apache2.conf
where you found out the/etc/apache2/envvars
-file, after reading the comments. Then you just used the/etc/init.d/apache2 restart
-command and verified that the program is actually running with intendeduser:group
.For newbies, I warn about
setuid/setgid
because easy security -vulnerabilities unless done carefully -- use as you wish with your own machine but use proper auditing in production. But this is no rocket-science! Thefind
-manual in Debian provided this tool that may help you in auditing things, have fuN!Traverse the filesystem just once, listing setuid files and directories into /root/suid.txt and large files into /root/big.txt.
find $HOME -mtime 0
Resumo
Now I have answered your points 1 and 3, about running a program with certain
user:group
-combination including Apache (q3 was a special case of question 1). So to the second question, a simplels
-command will make sure that Apache -thing is working correctly like this:# ls -lsa total 1832 4 drwxrwx--- 2 www-data web-content 4096 Aug 20 20:21 . 4 drwxrwx--- 6 www-data web-content 4096 Aug 14 22:20 .. 884 -rw-r--r-- 1 www-data web-content 900386 Aug 20 20:21 0_hhh.png 12 -rw-r--r-- 1 www-data web-content 8194 Aug 20 20:21 1_hhh.jpg
Happy puzzling :D
Comandos opcionais
You may need the following commands. If you need to add the user
www-data
into theweb-content
-group, for example because you eventually found a nice fellowA
with whom you want to co-operate. They may help you in debugging if something goes wrong, work hard!
It will add the www-data -user into the web-content -group.
# usermod -a -G web-content www-data
It will show you the user of the process but not the group
# ps -aux|grep apache