Ubuntu 19.10 - edit files owned by root

xrapidx

Honorary Master
Joined
Feb 16, 2007
Messages
42,219
Reaction score
4,062
Location
Cape Town
Can anyone help me out on running an app as sudo on Ubuntu 19.10? Trying to get Visual Studio Code to run as sudo, but - not coming right, google not helping much - everything I find refers to locations that don't exist, or don't have the required files.
 
It should be in your path so simply go to the terminal and do “sudo vmstudio” or whatever it’s call.

Try type visual and hit tab to get the name of the binary.

Why do you need to do this though? If it needs privileges it should simply pop up with the password prompt.
 
Last edited:
It should be in your path so simply go to the terminal and do “sudo vmstudio” or whatever it’s call.

Try type visual and hit tab to get the name of the binary.

Why do you need to do this though? If it needs privileges it should simply pop up with the password prompt.

Doesn't work. Still get prompted for username and password.

sudo code ---> then once open, try and save the file, and it prompts to retry as superuser.

Make sure that your user is part of the sudo group.

Also you should check that your have snap installed on your Linux by ensuring snapd is installed.

Don't think I want my useraccount in the group permanently.

Is this the instructions you followed?

Yip - installing's not the problem...


Will have a look.

What are you really trying to do?

See:

Two of the files I occasionally edit are owned by root - if I change their ownesrhip, it screws with the service (home-assistant).
 
So the problem is the file you are editing not the application.

Why do you need to edit files owned by root? And if you really need to can you give them other access or simply add your user to the group the files are assigned to instead?
 
Two of the files I occasionally edit are owned by root - if I change their ownesrhip, it screws with the service (home-assistant).

So don’t change their ownership.

Give yourself access to them.

Either add yourself to the group that owns the files (more secure).

Or open the permissions up so that you have access to it from any other user.

Or much simpler....don’t use Visual Studio and learn to vi or at worst nano.

sudo vi nameoffile

Will most definitely work.

If you really want to gui...

sudo gedit nameoffile

Otherwise if you want to go the permissions route...

ls -l nameoffile

IF you are the only user accessing this box and it’s only running at home and you are never going to apply any of this logic in a production system them simply do...

chmod 777 nameoffile

Now do...

ls -l nameoffile

You’ll notice that on the left it’s gone from rwx / rwx / r_x

To

rwx / rwx / rwx

Basically that reads as..

Owner / Group / Other

By doing chmod 777 you change the last Other bit so all users now have full access to it for writing not just reading and executing.

Not secure in general but probably just fine in your use case.

Otherwise you can add your own user to the group that has permission (likely root). OR you assign the file to a group where your user is already included.

The latter is the better way and won’t break anything as root remains the owner.

Basically you are looking for completely the wrong solution due to a fundamental lack of Linux understanding at present. Once you get the permissions structure it will make more sense.
 
Last edited:
Why would you want to do that?

Rather open VSC normally. You can then open the file(s) ( required by sudo ), and when you save them, it will pop up and ask if you want to save it as sudo and enter the password and save.

This won't change any rights.
 

Attachments

  • Screenshot from 2019-12-02 09-02-47.png
    Screenshot from 2019-12-02 09-02-47.png
    12.7 KB · Views: 10
Last edited:
I was using vi - it's a .js file - so the brackets, and getting the spacing readable get a bit much, hence installing VS Code.
 
Top
Sign up to the MyBroadband newsletter
X