日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux执行指定程序的命令,linux 下使用指定的用户来执行命令

發(fā)布時間:2024/1/23 linux 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux执行指定程序的命令,linux 下使用指定的用户来执行命令 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

有時間,我們需要在開機(jī)的時候執(zhí)行一些特定的程序或都腳本,因為涉及到安全主面的問題,所以又不想用root來執(zhí)行,那怎樣辦呢。

經(jīng)過查看 su 的幫助提示,發(fā)現(xiàn):

[root@redhat6?~]#?su?--help

Usage:?su?[OPTION]...?[-]?[USER?[ARG]...]

Change?the?effective?user?id?and?group?id?to?that?of?USER.

-,?-l,?--login???????????????make?the?shell?a?login?shell

-c,?--command=COMMAND????????pass?a?single?COMMAND?to?the?shell?with?-c

--session-command=COMMAND????pass?a?single?COMMAND?to?the?shell?with?-c

and?do?not?create?a?new?session

-f,?--fast???????????????????pass?-f?to?the?shell?(for?csh?or?tcsh)

-m,?--preserve-environment???do?not?reset?environment?variables

-p???????????????????????????same?as?-m

-s,?--shell=SHELL????????????run?SHELL?if?/etc/shells?allows?it

--help?????display?this?help?and?exit

--version??output?version?information?and?exit

A?mere?-?implies?-l.???If?USER?not?given,?assume?root.

Report?su?bugs?to?bug-coreutils@gnu.org

GNU?coreutils?home?page:?

General?help?using?GNU?software:?

For?complete?documentation,?run:?info?coreutils?'su?invocation'

發(fā)現(xiàn)其中重要的一行: "-c ?執(zhí)行單行命令"

哈哈,突破點(diǎn)。 馬上到命行里試一下:

[root@redhat6?~]#?su?-?admin?-c?"id"

uid=500(admin)?gid=500(admin)?groups=500(admin)

[root@redhat6?~]#

輸出的時?admin?在執(zhí)行命令?"id"?顯示的結(jié)果?,而且執(zhí)行后并沒有切換到"admin"?的console?下?.

#################### 找到方法了 ################

所以,在開機(jī)的時候在 /etc/rc.lcal 里面添加一句命令就可以實(shí)現(xiàn):開機(jī)時,使用一個普通用戶來幫我們做某些操作了 ....

[root@redhat6 ~]$ cat /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.

touch /var/lock/subsys/local

#input your command

su - admin -c "xxxxxx" ? //最好使用絕對路徑

#注: /etc/rc.local 是在所在的service 都啟動后,才會執(zhí)行的.

總結(jié)

以上是生活随笔為你收集整理的linux执行指定程序的命令,linux 下使用指定的用户来执行命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。