linux 下使用指定的用户来执行命令
2014-11-20 11:38
417 查看
有时间,我们需要在开机的时候执行一些特定的程序或都脚本,因为涉及到安全主面的问题,所以又不想用root来执行,那怎样办呢。
经过查看 su 的帮助提示,发现:
哈哈,突破点。 马上到命行里试一下:
#################### 找到方法了 ################
所以,在开机的时候在 /etc/rc.lcal 里面添加一句命令就可以实现:开机时,使用一个普通用户来帮我们做某些操作了 ....
[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 都启动后,才会执行的.
经过查看 su 的帮助提示,发现:
[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: <http://www.gnu.org/software/coreutils/> General help using GNU software: <http://www.gnu.org/gethelp/> For complete documentation, run: info coreutils 'su invocation'发现其中重要的一行: "-c 执行单行命令"
哈哈,突破点。 马上到命行里试一下:
[root@redhat6 ~]# su - admin -c "id" uid=500(admin) gid=500(admin) groups=500(admin) [root@redhat6 ~]# 输出的时 admin 在执行命令 "id" 显示的结果 ,而且执行后并没有切换到"admin" 的console 下 .
#################### 找到方法了 ################
所以,在开机的时候在 /etc/rc.lcal 里面添加一句命令就可以实现:开机时,使用一个普通用户来帮我们做某些操作了 ....
[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 都启动后,才会执行的.
相关文章推荐
- linux指定nologin用户执行命令
- Linux中使用指定用户运行命令
- linux下指定特定用户执行命令
- linux下管理员强行踢出用户的命令使用方法
- linux使用popen读取shell命令执行结果
- Linux:使用()执行一组命令
- linux中使用shell命令打开指定文件夹(Nautilus@GNOME)
- Linux怎样在某一特定时间执行命令(使用at”和“batch”)
- Linux:使用()执行一组命令
- java 使用jsch 远程链接linux执行命令
- 备份指定文件到用户主目录,使用tar命令压缩并发送邮件
- Linux 下使用Postgre中的命令,要使用postgres这个用户
- PHP执行linux系统命令的常用函数使用说明
- 在linux应用程序使用system函数执行简单的shell交互命令的方法
- linux下更改root用户的密码 以及VIM编辑器使用命令 :q,:x :w :q!
- java 使用jsch 远程链接linux执行命令
- Redhat Enterprise Linux中使用vsftpd搭建指定用户指定目录
- Linux下使用Shell命令控制任务Jobs执行
- 在linux中使用head命令和tail命令查看文件中的指定行
- Linux禁止非WHEEL用户使用SU命令