acess a protect folder using sudo in wsl - linux

i'm using linux shell in my windows (wsl) and i'm trying to make a cd to a directory that needs permission.
I've saw some solutions here including using sudo su, to became a super user, but even with this code i'm not sucessful
sudo su
cd ./rootfs
I'm stuck in this problem fro a while, so what's is going on?
root#LAPTOP-FGSL14B2:/mnt/c/Users/giova/Appdata/Local/Packages/CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc/LocalState# cd ./rootfs
bash: cd: ./rootfs: Permission denied

It is a special folder, see: superuser.com/a/1446574/1083266
(I wanted to mark the question as a duplicate, but that is only valid for existing answers on stackoverflow)

I suspect that the folder you are trying to access required elevated permissions to view. Is the shell running as admin?
Sudo will not elevate the shell to allow for access to windows folders that the process does not have access to.
In the start menu right click the wsl or bash exe and select "run as admin" see if that works for you.

Related

VS Code on linux, various permissions errors

Is there any way to get vs code to work properly in linux? I can't run sudo code . because that gives me an error saying it's not secure to do so, I can't do anything within the editor to force doing things, like staging a file in git, or reloading a newly installed extension. I've googled around, and it seems nobody else has posted about this, and it seems highly unlikely that I'm the first to raise issue about this. (Take it easy on me, I'm a relatively new linux user). I'm trying to figure this out on Ubuntu 18.04 if that's relevant at all. My version of vs code is 1.30.2
I guess my main question is what's the right way to get applications like vs code to be able to perform tasks that required doing things without fighting the OS about sudo and privileges?
Launch via sudo from terminal
To launch VSCode as root --which is highly discouraged-- you must specify an alternate user data directory as follows:
$ sudo code --user-data-dir /path/to/alternate/folder
VSCode will automatically generate the required folders in the selected directory and launch with root privileges.
Change permissions to fix "permission denied" error
The solution in this case is to manually change the permissions of the two directories /home/$USER/.config/Code/ and /home/$USER/.vscode/. Perform these steps:
$ sudo chmod 755 /home/$USER/.config/Code
$ sudo chmod 755 /home/$USER/.vscode
To answer your other question:
If you really need to run several commands as root and you are annoyed by having to enter your password several times (when sudo has expired), just do sudo -i and you'll become root.
If you want to run commands using pipes, use sudo sh -c "comand1 | command2".
You may also want to take a look at this Ask Ubuntu answer about running applications as root.
I solve this problem using:
sudo chown -R YOUR_USER YOUR_PROJECT/
You basically need to tell the OS that you are the owner of the files you create. Use sudo chown <user name> <projects directory>
However, if you already created some files before applying chown, don't forget to change their permission also sudo chown <user name> <projects directory>/<file name>.

ubuntu backup-manager Permission denied

I've recently installed backup manager onto my ubuntu machine to have automated backup going. The problem is when I go to set up the automatization using this code -
it comes us up saying this "bash: /etc/backup-manager.sh: Permission denied"
I do not understand this error. I've tried change the user who read/writes to someone other than root and that didn't work. I tried changed the chmod number from 770 to 700 and still didn't work.
any info on this is welcome. Thank you to those who help :)
those wondering I am using this tutorial giving to me by the host. https://documentation.online.net/en/dedicated-server/tutorials/backup/configure-backup/start
I'm using the desktop version of ubuntu 16 incase that is needed
The sudo doesn't do what you want in this case. What happens is that the shell evaluates the redirection and attempts to open the /etc/backup-manager.sh for you before the sudo cat even gets started. That fails because the shell still runs as you unprivileged user. You have to say sudo -i to open a new root shell, execute the commands and exit again.
Alternatively you could try sudo nano /etc/backup-manager.sh and paste the contents there. This would work because the editor is run as root and does the file opening itself when you save.

RStudio cannot reach .Rhistory on Ubuntu

I was working with markdown file on RStudio. I have Ubuntu 14.04 on my laptop. I produce html files using knitr. I decided to clean my enviroment and added rm and gc commands at the end.
Now here is a message in my console window:
Error attempting to read history from ~/.Rhistory: permission denied (is the .Rhistory file owned by root?)
What it means? Is it bad for my code?
You are right - the first time you ran it, you were in sudo mode, and the .Rhistory file was created with root as the owner. Running RStudio as root would remove the symptom, but is not ideal. To be able to run it as a regular user, simply change the owner of the .Rhistory file:
sudo chown -c <user_name> .Rhistory
In the best traditions of stackoverflow I reply to my own question! The problem occurred because when I first started R, I did it as su:
sudo R
so I can load a lot of useful libraries in /usr/lib/R/site-library and not in my account. As result .Rhistory became su file. It is possible for RStudio to see it if it is started as
sudo rstudio
and then all is fine.

Permissions Error in Perl Script for Linux

I'm trying to install the Touchmouse server for Linux. The software is a perl script that I have tried to run via terminal, using the perl command. The software I'm trying to run is here: https://github.com/mycroes/touchmoused
This is the output from terminal:
:~/Desktop/touchmoused-master$ perl touchmoused
Can't open /dev/uinput: Permission denied at touchmoused line 242.
:~/Desktop/touchmoused-master$ Established under name '<name of computer>'
I am new to Linux but have some experience with Terminal.
Thanks!
From the creator of the script:
Just download it, chmod +x and run it (as root, it needs access to /dev/uinput and it wants to register with avahi).
Regards,
http://blog.mycroes.nl/2011/04/touchmoused-logitech-touch-mouse-server.html
Your user won't have permissions for /dev/uinput, also check that /dev/uinput is the correct location for your distribution, the script allows you to override this with the -device flag.
So either make it executable so you don't have to enter 'perl' and then run with sudo or have root run it on startup.

SVN Post-Commit Hook to Publish Website?

I've got an SVN instance installed on a free EC2 AWS server. In short: I'm using LAMP.
Using what I read in this article and encountered the "you need a TTY" error as mentioned in the comments. I followed the second resource and it cleared the error message, but doesn't seem to be executing the script. When I manually run the script, however, it works.
Any clue what I'm missing?
When I followed the second resource to fix the TTY error I changed the contents of my /svn/repository/hooks/post-commit script from:
#!/bin/bash
sudo /usr/local/bin/svn-post-commit-update-mysite 1>&2
to:
#!/bin/bash
su –session-command=”/usr/local/bin/svn-post-commit-update-mysite 1>&2″ dynamic &
First possible issue:
You cannot rely on the value of the $PATH variable inside the hook. This means you need to specify complete paths for all executables.
In particular, "su" is a program located in "/bin/sh" in most distributions. To be sure, type
type su
Next possible issue:
Is your subversion server being run as root? su will try to ask for password if run by other users, and will fail if it's not being run interactively - even if the user is in the sudoers file!
If you are using Apache+DAV, this means the apache service must be run as root for this to work (instead of www-data), which is a serious security problem.
You probably don't need to use su or sudo at all if all of the files are owned by the same user (www-data, for instance). You can change the ownership of the site files with something like
sudo chown -R www-data:www-data /var/www/<my-project>
And then remove the sudo and su from both the hook and the svn-post-commit-update-mysite file.
My best guess would be that something in your script depends on the PATH environment variable. Subversion runs hooks in an empty environment for security reasons. So you need to either setup the environment in your shell script or use absolute paths.
You might want to read the Subversion book entry on implementing hook scripts. The particular issue I mentioned is explained in the information block.

Resources