解决银河麒麟kylin.desktop-generic编译生成的程序执行报错“权限不够”
编写一个简单的c程序
·
问题复现
编写一个简单的a.c程序
#include <stdio.h>
void main(){
printf("zzz\n");
}
编译该程序,生成a.out可执行程序
greatwall@greatwall-KVM-Virtual-Machine:~/cproj$ gcc a.c
greatwall@greatwall-KVM-Virtual-Machine:~/cproj$ ll
总用量 24
drwxrwxr-x 2 greatwall greatwall 4096 6月 9 14:49 ./
drwx------ 26 greatwall greatwall 4096 6月 9 14:39 ../
-rw-rw-r-- 1 greatwall greatwall 55 6月 9 14:38 a.c
-rwxrwxr-x 1 greatwall greatwall 9488 6月 9 14:49 a.out*
可以看到生成的a.out具备可执行权限
执行该程序
greatwall@greatwall-KVM-Virtual-Machine:~/cproj$ ./a.out
bash: ./a.out: 权限不够
报错
权限不够
解决方案
方案一:设置麒麟系统安全状态为Softmode
greatwall@greatwall-KVM-Virtual-Machine:~/cproj$ sudo setstatus Softmode
[sudo] greatwall 的密码:
greatwall@greatwall-KVM-Virtual-Machine:~/cproj$ getstatus
KySec status: Softmode
exec control: on
file protect: on
kmod protect: on
three admin : off
greatwall@greatwall-KVM-Virtual-Machine:~/cproj$ ./a.out
zzz
方案二:单独设置a.out文件kysec执行权限
greatwall@greatwall-KVM-Virtual-Machine:~/cproj$ sudo kysec_set -n exectl -v trusted ./a.out
[sudo] greatwall 的密码:
greatwall@greatwall-KVM-Virtual-Machine:~/cproj$ ./a.out
zzz
总结
1. 方案一适合用在开发环境,可有效避免编译生成的各类文件不可执行故障
2. 方案二适合Normal模式下,安装软件后为软件制定可执行权限
附件
kysec_set man手册
kysec_set(8) System Manager's Manual kysec_set(8)
NAME
kysec_set - set kysec label for specfied path(s)
SYNOPSIS
kysec_set [ -n part ] [ -r ] -v value path1 ..
DESCRIPTION
kysec_set set the kysec label of specified files or directories to
value. Kysec label is composed of three parts: identify part, pro‐
tect part and exectl part.
when not used with -n option, kysec label should be in such format:
"identify:protect:exectl". Set the new value to 'none' to clear the
corresponding part of kysec label.
for identify part, these values are valid:
secadm commands for secadm
audadm commands for auditadm
for exectl part, these values are valid:
unknown unknown files
original original system files
verified verified 3rd party files
kysoft software installer
trusted trusted files
for protect part, only readonly is valid.
OPTIONS
-n set specified part of kysec labels. part can be exectl,
userid or protect.
-r process labels recursively, only usable for directories.
-v the new label value
EE ALSO
getstatus(8), setstatus(8), kysec_get(8)
kysec_set(8)
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献14条内容
所有评论(0)