Error saying " "hosts" E212: Can"t open file for writing" when trying to change host name on the VM

0 votes

I have two VMs, one is the master and the other is the worker. I'm trying to create a kubernetes cluster. When I try to edit the hosts name, I get the following error:

"hosts" E212: Can"t open file for writing 
Dec 17, 2018 in Docker by Ali
• 10,450 points
1,266 views

2 answers to this question.

0 votes

Hey @Ali, Follow these steps:

 sudo su

When asked for password give the password.

After that to edit the hosts file using any one of the below commands:

nano /etc/hosts 

or 

vi /etc/hosts
answered Dec 17, 2018 by Arohi
Okayyy....but why was the error occurring in the first place?
Hey @Vardhan, You get this error when you don't have permissions or not running as a root user. Not just anyone can change the host name of the system. Hence using the sudo su command, you start accessing resources as a root user and it solves your issue.
0 votes
I am interested in the answer as well. I am having the same challenges on SLES12 SP3 when exditing files such as /etc/passwd, /etc/group, etc.. I provide the lsattr and the ls -l to disregard any comments on those two..

I am root.. I know, I logged in as root...

# lsattr /etc/passwd shows

---------------- /etc/passwd

# ls -l /etc/passwd
-rw-r--r-- 1 root root 1838 Jan 25 13:23 /etc/passwd

# lsof /etc/passwd
#                       ( <<- Nothing is returned)
answered Jan 26 by anonymous

Hey, You have read and write permissions as root. Open your etc/passwd file as root.

sudo vi etc/passwd

This should solve your problem. 

Related Questions In Docker

0 votes
1 answer

Error when trying to start host on Oracle Virtual Box

You have to enable the virtualization technology ...READ MORE

answered Dec 16, 2018 in Docker by Kiyara
243 views
0 votes
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17 in Others by anonymous
1,666 views
+3 votes
1 answer
0 votes
4 answers
0 votes
1 answer