I cannot open my /etc/hosts
file. I would very much like to, I have tried logging in as root and changing the ownership and changing the permissions, please help.
When I try to open the file I get:
-bash: /etc/hosts: permission denied
I cannot open my /etc/hosts
file. I would very much like to, I have tried logging in as root and changing the ownership and changing the permissions, please help.
When I try to open the file I get:
-bash: /etc/hosts: permission denied
Open a terminal and run the following command...
gksudo gedit /etc/hosts
This will open the file in gedit with root privileges allowing you to make your changes.
sudo nano -w /etc/hosts
. If you want to edit it with a graphical application, then we can troubleshoot the "cannot open display problem"; to do that, you should tell us how you are logged in? Are you logged in with a normal graphical session, or are you, for example, SSHing in remotely?
– Eliah Kagan
Jul 29 '13 at 22:02
nano
, or something else? Also, what do you mean when you say it doesn't have a list of your hosts? What are you expecting? The contents of a hosts
file usually look something like this. (By the way, if you just want to look at a file on the command line, you can use cat filename
, in this case cat /etc/hosts
.) You're typing commands into a terminal. How did you open that terminal?
– Eliah Kagan
Jul 29 '13 at 22:27
hosts
file the same way). You might want to back up the file first with the command sudo cp /etc/hosts /etc/hosts.old
. If you're not comfortable using a command-line text editor (nano -w
), and gksudo gedit /etc/hosts
does not work, then you can try sudo -H gedit /etc/hosts
. If that fails you can try sudo -i gedit /etc/hosts
. You should avoid running just sudo gedit /etc/hosts
; it's not likely to work any better and can cause problems.
– Eliah Kagan
Jul 31 '13 at 18:46
# The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters
Is this what it's supposed to look like?
When I did the gksudo one, the text editor came up with 2 tabs, one that looked like the stuff above, and another that never stopped loading. The sudo-H and sudo-i one just brought up 1 tab like the text above (which is hopefully in that grey box if I figured that out). I'm not sure if I type that line into the text above or the other tab that gksudo brought
gksudo
, sudo -H gedit
, and sudo -i gedit
are all working okay. When you use gksudo gedit
, you may get an extra tab in Gedit that doesn't have any document open it. That's normal; it's a known bug in Gedit. You can just use the tab that has your hosts
file in it, and ignore the empty one. It's normal for a hosts
file in Ubuntu to say "The following lines are desirable..." followed by those 5 lines. You should not change or remove those lines, but you can add more.
– Eliah Kagan
Jul 31 '13 at 20:40
In the terminal type:
$ sudo su
Type your password...
And you will get the root privileges. Then open the file via any text editor:
By GEdit
# gedit /etc/hosts
By mousepad ( sudo apt-get install mousepad )
# mousepad /etc/hosts
/etc/hosts
cannot be executed. It is not a program or script. On Windows, you can open a file by issuing the filename by itself as a command. On Ubuntu (and other Unix-like systems), you cannot -- issuing a filename as a command attempts to run a command of that name. – Eliah Kagan Jul 29 '13 at 22:01