通过本文操作,可以在fedora下的linux中,创建一个可以运行的bash脚本文件
一、将用户组改为root组【为了可使用sudo命令】
1、出现xx is not in the sudoers file 问题(转)
在执行sudo 命令时会出现xxx is not in the sudoers file. This incident will be reported.这样的错误输出。现在为了安全起见比较提倡使用普通用户做日常操作,而在需要超级用户的时候使用sudo 来做,这样,我们就有必要把一些用户添加到sudoers之中。
1、首先利用whereis 命令查找sudoers配置文件的目录(默认会在/etc/sudoers)
【embedclub@embedclub XX】$whereis sudoers
回显——sudoers: /etc/sudoers /etc/sudoers.bak /usr/share/man/man5/sudoers.5.gz
2、然后需要切换到root用户(多次摸索啊。。。小菜一枚)
输入【embedclub@embedclub XX】$ su root
输入密码:111111【换成你自己的】
就进入【root@embedclub XX】#
用exit退出。
3、更改/etc/sudoers的权限
【root@embedclub XX】# chmod u+w /etc/sudoers
4、然后就可以利用vi编辑器来把用户添加到sudoers之中
【root@embedclub XX】# vi /etc/sudoers
5、然后找到root
顺便提一下vi编辑器的用法。刚进入vi编辑器的时候牌命令行模式,这时可以通过方向键来移动光标,找到要编辑的位置之后按下“i”,然后就进入了插入模 式,这时候你可以输入或删除字符。编辑完成之后按“esc”键退出插入模式,进入命令行模式,这时候按“:”可以进入末行模式,输入“wq”保存并退出。
下面是添加完的结果。
## Allow root to run any commands anywhere
root
student
embedclub ALL=(ALL)
然后需要把sudoers 的写权限去掉(否则系统不允许执行suoders文件):
[root@embedclub XX]# chmod u-w /etc/sudoers
至此,在退出root用户之后就可以利用sudo命令来执行超级用户的权限了。
二、通过$sudo touch me创建一个me文件 该文件有没有给它后缀都可以,bash文件后缀是 。sh
三、修改me文件的操作权限【读、写、执行】
在terminal中输入$sudo chmod a+rwx me 。表示将me设置为user、group、other这三类访问者对该文件都有读写执行的权限。
用ls -l me可以查看当前该文件的操作权限是怎么样的。
四、增加me文件的内容,我用的是Vim编辑器
在terminal中输入vi me
进入Vim编辑器
输入:
#!/bin/bash
echo "Hello bash" #display one message
五、在Ternimal中运行该脚本
$./me
则会显示Hello bash