Home > Archives > Centos tmp 无法读写问题

Centos tmp 无法读写问题

Publish:

我遇到了一个奇葩的问题,我的/tmp目录,我用root登录进去,都不能读写,查看空间也都是有的,实在没有办法了,我改了系统默认的临时目录。

因为有很多程序都是要用这个临时目录的,所以,启动和执行,都是有问题的。

莫名其妙的 Permission denied

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[root@localhost tmp]# whoami
root
[root@localhost tmp]# touch a.txt
touch: cannot touch ‘a.txt’: Permission denied
[root@localhost tmp]# ll /
drwxrwxrwt.   8 root root    4096 Mar 16 21:49 tmp
[root@localhost tmp]# df /tmp
Filesystem              1K-blocks     Used Available Use% Mounted on
/dev/mapper/centos-root  52403200 31471560  20931640  61% /
[root@localhost tmp]# df -i /tmp
Filesystem                Inodes  IUsed    IFree IUse% Mounted on
/dev/mapper/centos-root 52428800 561646 51867154    2% /
[root@localhost tmp]# df -k /tmp
Filesystem              1K-blocks     Used Available Use% Mounted on
/dev/mapper/centos-root  52403200 31463432  20939768  61% /

解决办法

1
2
3
4
5
6
[root@localhost ~]# mkdir /temp
[root@localhost ~]# unset TEMP
[root@localhost ~]# unset TEPDIR
[root@localhost ~]# export TEPDIR=/temp
[root@localhost ~]# export TEMP=/temp
[root@localhost ~]# chmod -R 1777 /temp

解决方法二

1
[root@localhost ~]# chattr -i /tmp

扩展知识点

chattr 对文件更底层的保护

1
2
[root@localhost ~]# chattr +i /tmp 然后尝试rm, mv, rename等得到的都是Permission denied
[root@localhost ~]# chattr +a /var/nginx/error.log  表示只能追加,不能删除

lsattr 读取chattr配置的属性

参考

chattr和lsattr命令

声明: 本文采用 BY-NC-SA 授权。转载请注明转自: Ding Bao Guo