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.

migrated from stackoverflow.com Sep 13 '13 at 20:59

This question came from our site for professional and enthusiast programmers.

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

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

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.

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

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,

  • 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? – manguiti Sep 15 '13 at 19:27

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.