无法写入新创建的文件

Tho*_*ggi 0 ubuntu permissions

我有一个 ubuntu 服务器。我index.html使用touch. 并尝试使用nano,结果发现权限被拒绝。为什么是这样?如果我只是在服务器上创建文件,为什么我首先没有写访问权限?我的第二个问题是,如果我想更改数字格式的权限644(服务器上的 html 文件应该设置为什么?)我如何查看当前是什么我如何转换-rw-rw-r--为数字格式?我想-ls -l用数字权限格式而不是-rw-rw-r--. 该index.html文件在服务器上运行正常。

thomas@vannevar:~/public/example.org/public$ touch index.html
thomas@vannevar:~/public/example.org/public$ ls
index.html
thomas@vannevar:~/public/example.org/public$ nano index.html

Error reading /home/thomas/.nano_history: Permission denied

Press Enter to continue starting nano.

thomas@vannevar:~/public/example.org/public$ ls -l
total 0
-rw-rw-r-- 1 thomas thomas 0 May 17 13:57 index.html
thomas@vannevar:~/public/example.org/public$ 
Run Code Online (Sandbox Code Playgroud)

这有效

http://pricklytech.wordpress.com/2010/12/12/ubuntu-nano-error-reading-home-nano_history-permission-denied/

gpa*_*ent 7

您的问题是读取 nano 的历史文件 (.nano_history),正如在此大量空白错误行中非常清楚地指出的那样:

thomas@vannevar:~/public/example.org/public$ nano index.html

Error reading /home/thomas/.nano_history: Permission denied

Press Enter to continue starting nano.
Run Code Online (Sandbox Code Playgroud)

这是在 nano 打开文件之前打开的(工作正常,因为 644 可以)

看起来您的主文件夹/.nano_history 的权限可能设置得太紧了。


按照您的评论:

-rw------- 1 root root 111 May 17 14:13 /home/thomas/.nano_history

正如你所看到的,只有 root 的用户有读写权限,其他人没有。

你想sudo chown thomas:thomas ~/.nano_history解决这个问题。


Zor*_*che 5

鉴于您所展示的内容,您的问题几乎肯定与您sudo nano在过去的某个时间点使用编辑文件有关。Nano 在主目录中创建了一个历史文件,但具有 root 权限。

使用sudo rm /home/thomas/.nano_historysudo chown thomas:thomas /home/thomas/.nano_history修复该文件的权限。

如果您不小心,您使用 sudo 运行的许多程序可能会产生副作用,即在您的主目录中创建根拥有的文件。如果你知道这会发生在像 nano 这样的特定程序上,你最好使用sudo -iroot 环境启动一个新的 shell,然后运行你的命令。