---
title: "linux指定某非root用户执行开机启动项的方法"
author: "andyniu"
date: "2015-04-11T10:00:06Z"
tags: []
categories: ["操作系统"]
slug: "linux-root"
draft: false
lastmod: "2015-04-11T10:00:06Z"
id: 2201246
url: "https://andyniu.iteye.com/blog/2201246"
---

1、以linux下指定sun用户在linux开机时执行/home/sun/startrun.sh为例：

   以root登录linux

   执行vi /etc/rc.d/rc.local

   在文档末尾添加一行语句：su sun -c "/home/sun/startrun.sh"

   保存rc.local即可。

2、linux启动执行root脚本或命令时

touch /etc/rc.d/init.d/apache

#!/bin/bash  
      #Start httpd service  
      /server/apache/bin/apachectl start