--------------------------------------------------------------------------------------
Add a user (who isn’t root)
Add a new user to the
wheel
and apache
groups. The wheel
group gives root/sudo access. The apache
group allows both user and apache to write to your website files. The -G
tells useradd
we want to add to multiple groups. Sam is the username in this example.useradd -G wheel,apache us3r passwd us3r
Set directory and file permissions
Make apache the owner of
/var/www
. The -R
makes the ownership changes recursive (apply to all files and directories within /var/www
.
The syntax here is
user:group
. All users automatically have a group of the same name (e.g. user sam has a group called sam).chown -R apache:apache /var/www
Change the permissions to give the owner (apache) and members of the apache group write permission (775).
find /var/www/ -type f -exec chmod 664 {} \; find /var/www/ -type d -exec chmod 775 {} \;
Now resecure
/var/www
by giving it back to root
or the user you created earlier.chown root:root /var/www
View/confirm directory ownership/permissions with the
ls -l
command.ls -l /var ls -l /var/www
If you prefer editing long config files via S/FTP in a desktop text editor like Coda, take ownership of the following.
chown sam:sam /etc/php.ini chown sam:sam /etc/my.cnf chown -R sam:sam /etc/php.d chown -R sam:sam /etc/httpd
Give your new user root privileges
Start by using a special text editor
visudo
by issuing the following command.visduo
Enable the wheel group by uncommenting the following line like so.
## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL
Alternatively, uncomment the next line to enable the wheel group and allow these user to become root without having to renenter their password.
## Same thing without a password %wheel ALL=(ALL) NOPASSWD: ALL
Now logout of your SSH session, then test logging in as the new user.
logout ssh sam@YOUR_IP_HERE
Test that the new user can become
root
.sudo su -
The
#
should change to &
and the user should show root@YOUR_HOSTNAME
. Now logout of root to get back to your user.logout
For reference, you can also execute single line commands as root by prefixing with
sudo
e.g.sudo visudo
source http://whatsamknows.tumblr.com/post/40245741052/centos-lamp-permissions