I have a program that needs to access a file in my home directory.
Ubuntu will not allow this to happen due to the program not having root privileges. At first I ran this java command (which wouldn't work because the program did not have permission to access the files):
java -jar this.jar
The program was unable to detect the file I needed it to. The path that the program told me that it used was /home/myhome/directory
. This path was correct.
But then the program needed root privileges to actually access that file so I tried:
sudo java -jar this.jar
Then the directory that the program tried to access was /root/directory
this is the problem that I am having.
Is there any way that I can run a program as root with the directory the program views as the home
directory being the /home
directory instead of the /root
directory?
HOME
as being whatever path you give it as home. If this is not what you are asking for, then I did not understand your question. Let us know if this works.sudo
without the-H
option; try runningsudo echo $HOME
. Ifsudo
it's not explicitly told to set the environment differently, the environment from whichsudo
is invoked it's retained during the command execution. That's also the reason why running graphical applications withsudo
is discouraged, because root might end up owning files in the home directory, and also the reason why I think the problem is another one.sudo
,HOME
suddenly becomes that ofroot
. My system does not show that behavior at all. At Sock314: did you try this yet ?