chmod/chkconfig命令使用

1、chmod
linux文件调用权限分为三级,分别是文件拥有者、群组、其他人

chmod u+x test.sh  只给拥有者加上可执行权限

chmod g+x test.sh  只给群组身份加上可执行权限

chmod o+x test.sh  只给其他人身份加上可执行权限


chmod a+x test.sh      所有人拥有可执行权限

如果要去掉某个身份的某个权限,只需要将+变为-即可,例如去除其他人身份的可执行权限
chmod o-x test.sh        去除其他人的可执行权限

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/29820633/viewspace-2140545/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/29820633/viewspace-2140545/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是将这些命令转换为Python代码的示例: ```python import subprocess files_to_change_permissions = [ '/etc/passwd', '/etc/group', '/etc/shadow' ] for file_path in files_to_change_permissions: command = 'chmod 644 {}'.format(file_path) subprocess.call(command, shell=True) services_to_disable = [ 'rpcbind', 'printer', 'tftp', 'lpd', 'nfs', 'nfslock', 'ypbind', 'daytime', 'daytime-udp', 'sendmail', 'ntalk', 'ident', 'bootps', 'kshell', 'klogin', 'snmpd', 'time', 'time-udp', 'echo', 'echo-udp', 'discard', 'discard-udp', 'chargen', 'chargen-udp' ] for service in services_to_disable: command = 'chkconfig {} off'.format(service) subprocess.call(command, shell=True) systemd_services_to_disable = [ 'rpcbind', 'printer', 'tftp', 'lpd', 'nfs', 'nfslock', 'ypbind', 'daytime', 'daytime-udp', 'sendmail', 'ntalk', 'ident', 'bootps', 'kshell', 'klogin', 'snmpd', 'time', 'time-udp', 'echo', 'echo-udp', 'discard', 'discard-udp', 'chargen', 'chargen-udp' ] for service in systemd_services_to_disable: command = 'systemctl disable {}'.format(service) subprocess.call(command, shell=True) services_to_stop = [ 'rpcbind', 'snmpd' ] systemd_services_to_stop = [ 'telnet.socket', 'rlogin', 'rpcbind' ] for service in services_to_stop: command = 'service {} stop'.format(service) subprocess.call(command, shell=True) for service in systemd_services_to_stop: command = 'systemctl stop {}'.format(service) subprocess.call(command, shell=True) files_to_change_permissions = [ '/var/log/messages', '/var/log/secure', '/var/log/maillog', '/var/log/cron', '/var/log/spooler', '/var/log/boot.log' ] for file_path in files_to_change_permissions: command = 'chmod 600 {}'.format(file_path) subprocess.call(command, shell=True) ``` 上述代码使用了Python的`subprocess`模块来执行Shell命令。首先,通过遍历`files_to_change_permissions`列表,对每个文件执行相应的`chmod`命令来更改文件的权限。 接下来,通过遍历`services_to_disable`和`systemd_services_to_disable`列表,分别使用`chkconfig`和`systemctl disable`命令来禁用相应的服务。 然后,通过遍历`services_to_stop`和`systemd_services_to_stop`列表,使用`service`和`systemctl stop`命令来停止相应的服务。 最后,通过遍历`files_to_change_permissions`列表,对每个文件执行相应的`chmod`命令来更改文件的权限。 请确保你具有足够的权限来执行这些操作,并将需要更改权限的文件和需要禁用和停止的服务添加到相应的列表中。运行代码后,命令将被执行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值