0

To make the question better understood -> I currently have to run nano with sudo when i just want to run nano to edit a file.

So while I was fiddling with Ubuntu 20.04 in a VM I had everything more or less working in a way that I felt comfortable putting it onto an old laptop. In the VM I could just run ~$ nano , write what I wanted to into that file and then write out and save/exit nano and my file will be there. Now with the laptop that I put Ubuntu 20.04 on I need to run nano with sudo in order to write out and save/exit the file I was working on. When trying to edit my file 'Mounting a device' with just nano I am greeted with:

[File 'Mounting a device' is unwritable]

and if I try to write out I get:

[Error writting Mounting a device: Permission denied]

To be clear these aren't system files or config files or anything of that sort. These are files like "Bash commands and how to use", "How to mount a device", "test file 1", etc. Is it something to do with the user account I created or what could I have done wrong where?

I have only been using Ubuntu for about 6 months or so as my daily system so I'm still getting used to everything. I would like to be able to run nano to make day-to-day files and file edits without having to do it with sudo. Any idea on how I can change this?

The output of the ls -l is as follows:

peter@pbes:~/Documents/Bash command instructions$ ls -l
total 20
-rw-r--r-- 1 root root 351 Nov 1 08:35 AppImage
-rw-r--r-- 1 root root 570 Feb 5 00:20 Docker
-rw-r--r-- 1 root root 1030 Sep 23 23:59 'Mounting a device'
-rw-r--r-- 1 root root 442 Nov 8 21:13 PPA
-rw-r--r-- 1 root root 361 Oct 11 09:37 'Shutter install'

3
  • Why do you need to run nano with sudo? Why can't you run it under your own account? What's the difference between running it inside a VM and runnning it on bare metal? What are the permissions of the files you want to edit? What are the errors you see? Please try to be as accurate as possible, like why do you think you need it, what happen exactly when you run the command, any output you see on the screen, and what you've already tried to exactly.
    – aviro
    Feb 6, 2022 at 21:40
  • And just to clarify, you need to add those details to you question - edit your question and add those clarifications, you don't need to respond on the comment unless you have a question about my comment.
    – aviro
    Feb 6, 2022 at 21:42
  • 1
    Check the permissions of the directory and the files. Edit your question and add output of ls -l.
    – pLumo
    Feb 7, 2022 at 7:45

1 Answer 1

0

Those files don't belong to you - they belong to root:

-rw-r--r-- 1 root root 1030 Sep 23 23:59 'Mounting a device'
             ^owner

If that's not correct you need to change the ownership back to yourself. To change the directory and its files you can do this

  1. Change to the ~/Documents directory

     cd ~/Documents
    
  2. Change the ownership of the directory and all its contents. You will need to be root to do this (hence use of the sudo command), because taking or giving away files between owners is a privileged operation

    sudo chown -R "$USER" 'Bash command instructions'
    

    Here, the "$USER" is a variable that corresponds to your username. I could guess it's peter but to be sure the command will work I've just used a standard variable.

1
  • Ah perfect. That did solve my issue. Thank you.
    – Peter
    Feb 7, 2022 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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