I put ubuntu for the first time, then lamp server for php. You need to create a file in / var / www /. But neither the manual nor the terminal allows the system to do this. Then I wrote the sudo -i command in the terminal, assigning myself superuser rights. Now I can create a file in the terminal using the touch command.

The question remains - why can not I manually create a file, i.e. corny right-click, as in windows, to create a file. What is needed for this? How to assign yourself the right to permanent any actions with folders and files?

  • the question is unclear. After all, you created the file "manually". - aleksandr barakin 7:09
  • edited the description of the subject matter - Beginner

3 answers 3

I put ubuntu for the first time, then lamp server for php. Need to create a file in / var / www /

Assign your site's docroot to a directory inside your home directory:

 DocumentRoot /home/пользователь/www 

where /home/пользователь is your home directory. the web server will then need to be restarted.

Well, do not forget to create this directory ("mouse" or "manually": mkdir ~/www ).

now without any “additional rights” you can create / edit / delete files / directories of your site.

  • Thank you, but it's understandable. It is interesting for me to access the default directory / var / www / and get there the opportunity to do manipulations with folders and files - Beginner
  • one
    the one I proposed is the most “correct” option. what is offered to you in other answers (to make the catalog writable by all users) is absolutely “wrong”. a little less “wrong” (but also very bad) - make your user the owner of the /var/www directory: sudo chown -R $USER /var/www . - aleksandr barakin
  • 2
    Your desire to transfer "as is" habits from one operating system to another is completely understandable, but, alas, meaningless. Try to get "new habits", more suitable to the new environment. - aleksandr barakin
  • Well, so there is no user. I want to do for myself as a laptop owner. - Beginner
  • one
    users in your machine are much more than one. you can calculate for yourself: wc -l /etc/passwd - aleksandr barakin

Because by default, the file manager of your OS does not start with root privileges. And the directory in which you want to create a file does not allow you to do this because your user does not have write permissions.

To resolve this issue, you need to either assign write access to this directory using the chmod utility:

 $ sudo chmod ugo+w /var/www/ 

Or, locally in the terminal, use sudo to execute the touch command with superuser rights:

 $ sudo touch FILENAME 

however, you must perform these actions with sudo every time you create a file.

The system prohibits the recording of data primarily to ensure their internal security. You can read more about the chmod (english) utility: Archwiki :: File permissions and attributes.

  • oh, it came out using $ sudo chmod ugo + w / var / www /. thank! I now manually created the file, made the code there, but does not save the file. What to do? Should I have added something to this command $ sudo chmod ugo + w / var / www / to allow writing to a file and saving it? - Beginner
  • Can you give an error text to the prompt? - igrikxd
  • I did not give any error. Just in the file that was opened with the gedit text editor, the "Save" button is hammered, not clickable, i.e. save can not change there. - Beginner
  • So you still do not have the right to write to this directory, check the write rights for this directory: - IgrikXD
  • sudo ls -ld / var / www / - IgrikXD

How to assign yourself the right to permanent any actions with folders and files?

The easiest option is to assign a root password:

 sudo passwd root 

Log out of the graphical environment and log in as root. Then there will be no restrictions on working with files and folders in a graphical environment, you can create files in any folder with a mouse.

But, of course, this option is not recommended. It is better to use a separate file manager, which will be loaded with superuser rights:

 sudo mc 

Open two-pane management similar to FAR in Windows.

 sudo krusader 

A manager similar to total comander will open, launching it in this way - there will be no restrictions on working with files.

Well, you only need to pre-install them for this:

 sudo apt-get install mc krusader 

If the two-pane is not needed, you can run the usual one:

 sudo nautilus 

In the file manager window that opens, there will be unlimited rights, you can create and edit files with a mouse without requesting superuser rights.

  • I do not agree with you. There are no special file managers for sudo. Absolutely anyone will do; you don't need to install anything else here (of course you can, but this does not apply to the question). - Beast Winterwolf