标签:su
CentOS 6.5测试发现,rc.local里不能使用sudo,可以使用su
但有个前提条件,指定的用户可以不用建立家目录,但必须是可以登录的
[root@Lab2 ~]# vim /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don‘t
# want to do the full Sys V style init stuff.
/bin/su - svn -c "svnserve -d -r /application/svndata/"
重启后
[root@Lab2 ~]# ps -ef|grep svn
svn 1561 1 0 11:52 ? 00:00:00 svnserve -d -r /application/svndata/
root 1603 1583 0 11:53 pts/0 00:00:00 grep svn
有些网友的笔记是用su <user>这种形式(少了一个-号),其实也是可以启动的,但是否用-号还是有些区别的
不带-号
[root@Lab2 ~]# su svn
[svn@Lab2 root]$ echo $PATH
/application/mysql/bin:/application/mysql/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
带-号
[root@Lab2 ~]# su - svn
[svn@Lab2 ~]$ echo $PATH
/application/mysql/bin:/application/mysql/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/svn/bin
PATH路径有所不同,只有带减号才算是完整的切换身份。
标签:su
原文地址:http://coosh.blog.51cto.com/6334375/1834262