I created a file using

sudo vim filename

but I can't modify it after creating.

How can I make it possible to modify this file?

  • have you tried sudo chmod u+w filename?
    – andrybak
    Apr 9, 2015 at 7:34
  • @MohamedRamzyHelmy How are you editing it? If you create a file with using sudo privilege, you must use sudo to open it; then you will able to edit it again. why? Apr 9, 2015 at 8:38

1 Answer 1


By executing this command

sudo vim filename

you create new file, whose owner is the root user. You can confirm that by executing ls -al. From the output you can see that the owner and the group to which the file belongs are set to root.

If you try to edit it with your normal user, you wont be able, because the file does not belongs to your user. Again you are able to read the file but not write to it, because of the permissions. You can check them to from the command line with ls -al command. It should be something like:

-rw-r--r-- 1 root   root       4 Apr  9 07:40 filename

the first part -rw-r--r-- means that only owner can read and write to file, users from the same group and other user can only read the file.

Here is a good diagram that describes the meaning of permissions:


If you wish to be able to edit the file, you must do so as the root user - this is almost always the best way:

sudo vim filename

If you wish to edit it as normal user you can assign additional permissions to it, (but you should not do this to system files outside your home directory - use sudo to edit them instead):

sudo chmod 777 filename

This way the file will be readable, writable and executable from every user. This is rarely a good idea.

To give ONLY write permissions to all other users:

sudo chmod o+w filename

Otherwise if you want the file to be writable only by you, you can change the owner to you:

sudo chown yourusername:root filename

You must log in to answer this question.

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