简体   繁体   English

在mac os x上运行cf命令时获取权限被拒绝错误

[英]Getting permission denied error when running cf command on mac os x

I have installed Cloud Foundry CLI package on my Mac OS X Yosemite. 我在Mac OS X Yosemite上安装了Cloud Foundry CLI软件包。 From the terminal interface when I type cf command, I get the following error 当我键入cf命令时,从终端界面,我得到以下错误

FAILED
Error read/writing config:  open /Users/viyer/.cf/config.json: permission denied

How do I fix this? 我该如何解决? I can't find the file config.json . 我找不到文件config.json

I found that removing the .cf directory then running the cf cli fixed it 我发现删除.cf目录然后运行cf cli修复了它

sudo rm -r ~/.cf
cf -h

That was a bit weird, but I solved it by assigning 777 permission to the folder and config.json. 这有点奇怪,但我通过为文件夹和config.json分配777权限来解决它。

So, sudo chmod 777 .cf/config.json resolved the problem in my case. 所以, sudo chmod 777 .cf/config.json解决了我的问题。

Give it a try! 试试看!

Cheers! 干杯!

By default, the cf CLI will try to create and write to a directory named .cf in the user's home directory (ie ~/.cf ). 默认情况下, cf CLI将尝试创建并写入用户主目录中名为.cf的目录(即~/.cf )。 For some reason the user on your machine doesn't have permissions to create and/or write to that directory. 由于某种原因,您计算机上的用户无权创建和/或写入该目录。

You can work around this problem by setting the CF_HOME environment variable to another directory that the user does have permissions in. 您可以通过将CF_HOME环境变量设置为用户具有权限的另一个目录来解决此问题。

Unfortunately, no amount of changing permissions on my El Capitan would enable cf to access the config.json file in the .cf folder. 不幸的是,我的El Capitan上没有任何更改权限会使cf访问.cf文件夹中的config.json文件。 I created a new folder in my home space ("CLI") and ensured it had the right permissions and set CF_HOME to point to "~/CLI/" . 我在我的家庭空间(“CLI”)中创建了一个新文件夹,并确保它具有正确的权限并将CF_HOME设置为指向“〜/ CLI /”。 Just creating the new CF_HOME folder and setting CF_HOME in my .bash.profile was insufficient. 只是创建新的CF_HOME文件夹并在我的.bash.profile中设置CF_HOME是不够的。 I then copied the contents of the .cf folder into my new CLI folder. 然后我将.cf文件夹的内容复制到我的新CLI文件夹中。 Finally! 最后! cf is working! cf正在运作!

Oh, this is interesting. 哦,这很有趣。 CF on this version of OSX will only run from the home directory, it won't run (it won't find config.json) from anything other than root. 此版本的OSX上的CF只能从主目录运行,它不会从root以外的任何东西运行(它不会找到config.json)。

Try this command: sudo chmod -R 777 /Users/{username}/.cf 试试这个命令: sudo chmod -R 777 /Users/{username}/.cf

It worked for me on OS X El Capitan. 它在OS X El Capitan上为我工作。

The config.json need to have read and write permissions, in my case the .cf folder has root as owner and staff as group, my user on my Mac Yosemite is part of the group staff, but still the config.json file has permission set to 600 to fix this problem you should do: config.json需要具有读写权限,在我的情况下,.cf文件夹将root作为所有者,工作人员作为组,我的Mac Yosemite上的用户是组员工的一部分,但是config.json文件仍有权限设置为600 以解决此问题,您应该这样做:

sudo chmod 666 /User/YourUser/.cf/config.json

Also check the permissions of the .cf folder and check if you can read and write. 还要检查.cf文件夹的权限,并检查是否可以读写。 Do something like this: sudo chmod 755 /User/YourUser/.cf 做这样的事情: sudo chmod 755 /User/YourUser/.cf

Delete all the .cf folders from your system and try again. 从系统中删除所有.cf文件夹,然后重试。 This is something which @broomyocymru has already mentioned above. 这是@broomyocymru上面已经提到的。 But still felt this might help users who might not be familiar with shell commands 但仍然觉得这可能会帮助那些可能不熟悉shell命令的用户

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM