2

I'm new to linux. I downloaded an image of ubuntu 12 for VirtualBox and I want to configure the .ssh/config file to access via ssh to an application in development.

I access /home/ubuntu folder and I login as root, I type vim .ssh/config and when I save I get the error: .ssh/config E212: Can not open file for writing. Y saved it with :w, :w!, :wq! and I can´t.

I tried with sudo .ssh/config and sudo ~/.ssh/config.

I've tried different virtual machines so i don't know can be causing this error. I hope you can help me.

2
  • Open your editor as root user.
    – Jeffrey A.
    Sep 13, 2013 at 18:05
  • 1
    Are you trying to configure the ~/.ssh/config? If so, you should't need to be root.
    – user2062950
    Sep 13, 2013 at 18:12

4 Answers 4

6

If the .ssh folder didn't exist you could get this.

In which case you could create it first with:

mkdir ~/.ssh
chmod 700 ~/.ssh
0

When using vi on files with elevated permissions you have to use sudo

For example you must use sudo vi .ssh/config

This is because the .ssh directory or the .ssh/config file must be owned by root and when using the sudo command it elevates your privileges to root for the duration of that process.

1
  • Yes, I tried it too... but I have the same problem.
    – user1895775
    Sep 13, 2013 at 18:18
0

You can be probably in read mounted filesystem though you can try the following steps For some reason the file you are writing to cannot be created or overwritten. The reason could be that you do not have permission to write in the directory or the file name is not valid.

Vim has a builtin help system, I just quoted what it says to :h E212. You might want to edit the file as a superuser like sudo vim FILE. Or if you don't want to leave your existing vim session (and know have proper sudo rights), you can issue:

:w !sudo tee % > /dev/null Which will save the file. I found this on https://stackoverflow.com/questions/8253362/etc-apt-sources-list-e212-cant-open-file-for-writing

Thanks & Regards,
Alok

1
  • Thanks for your response, but I still have problem to save it. I typed that and this is the output: :w !sudo tee % > /dev/null tee: .ssh/config: No such file or directory shell returned 1 How can I know if the image is for readonly ? ¿Can someone link a image without this problem?
    – Lorraine
    Sep 15, 2013 at 19:27
0

Go to C:\Users\user\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\user.ssh and make sure you can't see any config file with the windows explorer, in my case there was already one config file, which i was not able to see it via ubuntu terminal

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .