Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission issues using file_puts_contents on /etc/hosts #5

Open
sirolad opened this issue Jul 8, 2017 · 8 comments
Open

Permission issues using file_puts_contents on /etc/hosts #5

sirolad opened this issue Jul 8, 2017 · 8 comments

Comments

@sirolad
Copy link

sirolad commented Jul 8, 2017

Because I use sudo to access my /etc/hosts file, writing to it from line 133 is returning permission denied. Is there a way around this without 'chmod-ing' my hosts file?

@kilroyweb
Copy link
Owner

I had to play around with permissions a bit as well so I'm not too sure of a perfect solution.

I'll keep this open for now though in case anyone else has any good ideas since I'd also like to get some good documentation in place for any prep needed to the hosts file.

@ligne13
Copy link

ligne13 commented Jul 10, 2017

+1

@TTiger
Copy link

TTiger commented Aug 8, 2017

sudo chmod 664 /etc/hosts works for me on Mac.
Once you make it writable by the wheel group ( of which most admin users are a member ) you'll have permissions to write to it. Should only have to do it once.

@Eduruiz
Copy link

Eduruiz commented Aug 15, 2017

@TTiger better solution than mine, I was just sudo homeboy'ing to get it working.

@kilroyweb
Copy link
Owner

Thanks all, I think it's pretty safe to close this for now since it's more of a platform / permissions related issue.

I made a small note in the Troubleshooting section of the ReadMe with the chmod settings from @TTiger

@Kehet
Copy link
Contributor

Kehet commented Aug 26, 2017

Please note that adding more permissions to /etc/hosts may make your system vulnerable to DNS hijacking attack since /etc/hosts is preferred over any DNS server

Better solution would be to trigger sudo prompt, maybe something bit like this

<?php

namespace App\FileManagers;

class HostsFileManager extends BaseFileManager {

    public function appendLine($line)
    {
        // Do we need to sanitize these variables? Probably yes
        return exec('echo "' . $line . PHP_EOL . '" | sudo tee -a ' . $this->filePath);
    }

}

(Only works for Linux and OSX)

@kilroyweb
Copy link
Owner

Thanks Kehet, I'll keep this open for now and see if we can get an update in place for Linux/OSX

@Eduruiz
Copy link

Eduruiz commented Sep 28, 2017

and I'm back using sudo homeboy, with sudo it works like it should, but is not a good thing to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants