使用新用户运行时,Wget 无法写入文件.如何解决? [英] Wget cannot write files when run with a new user. How to fix it?
问题描述
我在 Ubuntu 中有一个名为 my_account
的用户帐户.然后我创建了另一个名为 test_account
的帐户.当我在 my_account
中执行 wget 时,它可以工作:
I had a user account in Ubuntu called my_account
. Then I created another account called test_account
. When I do wget in my_account
, it works:
my_account@my_machine:~$ wget --no-check-certificate https://hdfs_server:50470/webpage.html#tab-datanode
--2018-02-09 14:37:30-- https://hdfs_server:50470/webpage.html
Resolving hdfs_server (hdfs_server)... 192.168.xx.xx
Connecting to hdfs_server (hdfs_server)|192.168.xx.xx|:50470... connected.
WARNING: cannot verify hdfs_server's certificate, issued by ‘CN=abc CA3,DC=def,DC=ghi,DC=org,DC=jkl’:
Self-signed certificate encountered.
WARNING: cannot verify hdfs_server's certificate, issued by ‘CN=abc CA3,DC=def,DC=ghi,DC=org,DC=jkl’:
Self-signed certificate encountered.
HTTP request sent, awaiting response... 200 OK
Length: 13320 (13K) [text/html]
Saving to: ‘webpage.html’
webpage.html 100%[===================>] 13.01K --.-KB/s in 0.002s
2018-02-09 14:37:30 (5.33 MB/s) - ‘webpage.html’ saved [13320/13320]
但是当我在 test_account
中执行 wget 时,它给出了这个错误:
But when I do wget in test_account
, it gives this error:
test_account@my_machine:~$ wget --no-check-certificate https://hdfs_server:50470/webpage.html#tab-datanode
--2018-02-09 14:29:52-- https://hdfs_server:50470/webpage.html
Resolving hdfs_server (hdfs_server)... 192.168.xx.xx
Connecting to hdfs_server (hdfs_server)|192.168.xx.xx|:50470... connected.
WARNING: cannot verify hdfs_server's certificate, issued by ‘CN=abc CA3,DC=def,DC=ghi,DC=org,DC=jkl’:
Self-signed certificate encountered.
HTTP request sent, awaiting response... 200 OK
Length: 13320 (13K) [text/html]
webpage.html: Permission denied
Cannot write to ‘webpage.html’ (Success).
我使用 test_account
作为超级用户(即 su test_account
).那么,为什么wget 不能用test_Account
将文件写入系统呢?我该如何解决?
I am using test_account
as superuser (i.e., su test_account
). So, why can't wget write files into the system with test_Account
? And how can I fix it?
推荐答案
我找到了原因.事实证明,test_account
在创建时没有正确设置 sudo useradd -m -d/home/test_account test_account
,如 之间所有者的差异所示my_account
和 test_Account
:
I found the reason. Turns out, test_account
was not set up properly when created like so sudo useradd -m -d /home/test_account test_account
, as shown by the differences in owners between my_account
and test_Account
:
my_Account@my_machine:~$ ls -la
total 120
drwxr-xr-x 30 root root 4096 Feb 7 16:02 .
drwxr-xr-x 26 root root 4096 Jan 28 06:44 ..
drwxr-xr-x 4 1026 1026 4096 Feb 9 14:12 test_account
drwxr-xr-x 23 my_account my_account 4096 Feb 9 14:37 my_account
可以看出,test_account
没有任何所有者,而 my_Account
有.因此,为了解决此问题,我执行了以下操作:
As can be seen, test_account
does not have any owner, while my_Account
does. So, to fix this, I did the following:
my_Account@my_machine:~$ su - root
Password:
root@my_machine:/home# chown test_account:test_account test_account
之后,我们可以看到 test_account
属于正确的组,并且 wget 起作用了:
After this, we can see that test_account
belongs to the proper group, and wget works:
root@my_machine:/home# ls -la | grep test_account
drwxr-xr-x 4 test_account test_account 4096 Feb 9 14:12 test_account
root@my_machine:/home# exit
exit
my_account@my_machine:~$ exit
logout
test_account@my_machine:~$ wget --no-check-certificate https://hdfs_server:50470/webpage.html#tab-datanode
--2018-02-09 14:37:30-- https://hdfs_server:50470/webpage.html
Resolving hdfs_server (hdfs_server)... 192.168.xx.xx
Connecting to hdfs_server (hdfs_server)|192.168.xx.xx|:50470... connected.
WARNING: cannot verify hdfs_server's certificate, issued by ‘CN=abc CA3,DC=def,DC=ghi,DC=org,DC=jkl’:
Self-signed certificate encountered.
WARNING: cannot verify hdfs_server's certificate, issued by ‘CN=abc CA3,DC=def,DC=ghi,DC=org,DC=jkl’:
Self-signed certificate encountered.
HTTP request sent, awaiting response... 200 OK
Length: 13320 (13K) [text/html]
Saving to: ‘webpage.html’
webpage.html 100%[===================>] 13.01K --.-KB/s in 0.002s
2018-02-09 14:58:01 (5.26 MB/s) - ‘webpage.html’ saved [13320/13320]
只是想我应该发布我的解决方案,以防有人遇到同样的问题.
Just thought I should post my solution in case someone facing the same issue might stumble upon it.
这篇关于使用新用户运行时,Wget 无法写入文件.如何解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!