您的位置:首页 > 运维架构 > Apache

修改apache的默认用户和组

2015-09-24 11:41 459 查看
修改apache的默认用户和组

##更改前查看apache的用户和组

egrep -i "user|group" httpd.conf |egrep -v "#|^$"
ps -ef |grep httpd

[root@LAMP conf]# egrep -i "user|group" httpd.conf |egrep -v "#|^$"
User daemon
Group daemon

[root@LAMP lib]# ps -ef |grep httpd
root 43329 1 0 11:09 ? 00:00:00 /application/apache/bin/httpd
daemon 43331 43329 0 11:09 ? 00:00:00 /application/apache/bin/httpd
daemon 43332 43329 0 11:09 ? 00:00:00 /application/apache/bin/httpd
daemon 43333 43329 0 11:09 ? 00:00:00 /application/apache/bin/httpd
daemon 43334 43329 0 11:09 ? 00:00:00 /application/apache/bin/httpd
root 43455 3916 0 11:28 pts/1 00:00:00 grep httpd
[root@LAMP lib]#
#######################
创建用户和组
useradd -s /sbin/nologin -M apache
tail -1 /etc/passwd
###
[root@LAMP ~]# useradd -s /sbin/nologin -M apache
[root@LAMP ~]# tail -1 /etc/passwd
apache:x:502:502::/home/apache:/sbin/nologin

######更改apache的用户和组
egrep -i "user|group" httpd.conf |egrep -v "#|^$"
sed -i 's/User daemon/User apache/g' httpd.conf
sed -i 's/Group daemon/Group apache/g' httpd.conf
egrep -i "user|group" httpd.conf |egrep -v "#|^$"
###
[root@LAMP conf]# egrep -i "user|group" httpd.conf |egrep -v "#|^$"
User daemon
Group daemon
[root@LAMP conf]#
[root@LAMP conf]# sed -i 's/User daemon/User apache/g' httpd.conf
[root@LAMP conf]# sed -i 's/Group daemon/Group apache/g' httpd.conf
[root@LAMP conf]# egrep -i "user|group" httpd.conf |egrep -v "#|^$"
User apache
Group apache

#######重启apache测试是否更改成功
/application/apache/bin/apachectl graceful
ps -ef|grep http
###
[root@LAMP conf]# /application/apache/bin/apachectl graceful
[root@LAMP conf]# ps -ef|grep http
root 43329 1 0 11:09 ? 00:00:00 /application/apache/bin/httpd
apache 43480 43329 0 11:36 ? 00:00:00 /application/apache/bin/httpd
apache 43481 43329 0 11:36 ? 00:00:00 /application/apache/bin/httpd
apache 43482 43329 0 11:36 ? 00:00:00 /application/apache/bin/httpd
apache 43483 43329 0 11:36 ? 00:00:00 /application/apache/bin/httpd
root 43566 3916 0 11:36 pts/1 00:00:00 grep http
[root@LAMP conf]#

全部命令
###查看是否存在apache用户,没就创建apache用户和组
cat /etc/passwd
useradd -s /sbin/nologin -M apache
tail -1 /etc/passwd
##查看现在的apache的用户和组是什么
ps -ef |grep httpd
cd /application/apache/conf/
egrep -i "user|group" httpd.conf |egrep -v "#|^$"
##更改apache的用户和组
sed -i 's/User daemon/User apache/g' httpd.conf
sed -i 's/Group daemon/Group apache/g' httpd.conf
egrep -i "user|group" httpd.conf |egrep -v "#|^$"

##重启看是否更改成功
/application/apache/bin/apachectl graceful
ps -ef|grep http

本文出自 “奋斗吧” 博客,请务必保留此出处http://lvnian.blog.51cto.com/7155281/1697764
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: