Bonjour à tous,
Je souhaite donner les droits à apache d'executer un script shell qui contient une commande (entre autres) useradd.
Le problème est qu'il ne veut pas donner les droits pour useradd.
Voici le contenu de mon script shell :
#!/bin/bash
useradd $1 -g etudiants
mkdir /web/$1
chown $1 /web/$1
chgrp apache /web/$1
chmod 777 /web/$1/
usermod -d /web/$1 $1
echo $2 | passwd $1 --stdin
Le contenu du visudo :
## Networking
Cmnd_Alias NETWORKING = /sbin/route, /sbin/ifconfig, /bin/ping, /sbin/dhclient, /usr/bin/net, /sbin/iptables, /usr/bin/rfcomm, /usr/bin/wvdial, /sbin/iwconfig, /sbin/mii-tool
## Installation and management of software
Cmnd_Alias SOFTWARE = /bin/rpm, /usr/bin/up2date, /usr/bin/yum
## Services
Cmnd_Alias SERVICES = /sbin/service, /sbin/chkconfig
## Updating the locate database
Cmnd_Alias LOCATE = /usr/sbin/updatedb
## Storage
Cmnd_Alias STORAGE = /sbin/fdisk, /sbin/sfdisk, /sbin/parted, /sbin/partprobe, /bin/mount, /bin/umount
## Delegating permissions
Cmnd_Alias DELEGATING = /usr/sbin/visudo, /bin/chown, /bin/chmod, /bin/chgrp
## Processes
Cmnd_Alias PROCESSES = /bin/nice, /bin/kill, /usr/bin/kill, /usr/bin/killall
Cmnd_Alias USERS = /usr/sbin/useradd, /usr/sbin/userdel, /usr/sbin/usermod, /bin/chown
## Drivers
Cmnd_Alias DRIVERS = /sbin/modprobe
# Defaults specification
#
# Disable "ssh hostname sudo <cmd>", because it will show the password in clear.
# You have to run "ssh -t hostname sudo <cmd>".
#
#Defaults requiretty
Defaults env_reset
Defaults env_keep = "COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR \
LS_COLORS MAIL PS1 PS2 QTDIR USERNAME \
LANG LC_ADDRESS LC_CTYPE LC_COLLATE LC_IDENTIFICATION \
LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC \
LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS \
_XKB_CHARSET XAUTHORITY"
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
apache ALL=(ALL)NOPASSWD: /scripts/create_comptes.sh
apache ALL=(ALL)NOPASSWD: /scripts/delete_compte.sh
apache ALL=(ALL)NOPASSWD: USERS
## Allows members of the 'sys' group to run networking, software,
## service management apps and more.
# %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
## Allows people in group wheel to run all commands
# %wheel ALL=(ALL) ALL
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
## Allows members of the users group to shutdown this system
# %users localhost=/sbin/shutdown -h now
et enfin... mon erreur :x
[root@pedagogie6 scripts]# su apache
bash-3.2$ sudo /scripts/create_comptes.sh test8 test8
/scripts/create_comptes.sh: line 2: useradd: command not found
mkdir: ne peut créer le répertoire `/web/test8': Le fichier existe.
chown: `test8': usager invalide
/scripts/create_comptes.sh: line 8: usermod: command not found
passwd: Unknown user name 'test8'.
ps :
[root@pedagogie6 scripts]# which useradd
/usr/sbin/useradd
[root@pedagogie6 scripts]# cat /etc/passwd | grep "apache"
apache:x:48:48:Apache:/var/www:/bin/bash
Merci d'avance pour votre aide