I’m running the latest MATE on a Raspberry Pi 3. I have a strong Windows background, but zero knowledge on the Lunix side.
I’m simply wanting to run a chown command at startup, against a specific folder. I’ve read many guides, which suggest editing /etc/rc.local, or creating a script.sh file and putting this in /etc/init.d/ however none of the methods I’ve tried seem to work.
Given this should be a 2 minute job for a guru, I was wondering if someone could hold my hand?
The command I’m trying to run is;
“sudo chown -R user:user /etc/path/to/directory/”
May I ask why you want to do that?
chown is persistent, is another process changing the ownership of the directory?
The methods you’re attempting to use are the old way of doing things (upstart), recent Ubuntu releases now use systemd, you need to adapt the instructions to the new system, see here:
https://wiki.ubuntu.com/SystemdForUpstartUsers
My lack of linux knowledge knows no other way. But yes you’re right.
I’m wanting to ‘own’ the configurations directory of OpenHAB, /etc/openhab/configurations/, so that I can edit the config files remotely.
Currently, when I reboot my Pi, OpenHAB starts, and part of its startup procedure must be to revert the ‘ownership’ of the configurations directory.
#!/bin/sh
# Read configuration variable file if it is present
[ -r /etc/default/openhab ] && . /etc/default/openhab
OPENHAB_CONF_DIR="/etc/openhab"
#OPENHAB_CONFIGURATIONS_DIR="${OPENHAB_CONF_DIR}/configurations"
OPENHAB_DIR="/usr/share/openhab"
OPENHAB_LOG_DIR="/var/log/openhab"
OPENHAB_HOME_DIR="/var/lib/openhab"
OPENHAB_USER_DATA_DIR="${OPENHAB_HOME_DIR}"
OPENHAB_WORKSPACE_DIR="${OPENHAB_HOME_DIR}/workspace"
JETTY_CONFDIR="${OPENHAB_CONF_DIR}/jetty/etc"
if [ -z "$USER_AND_GROUP" ]; then
USER_AND_GROUP="openhab:openhab"
fi
Commenting out the #OPENHAB_CONFIGURATIONS_DIR line in the file /usr/share/openhab/bin/openhab.in.sh seems to have helped. Although I’m sure if I update OpenHAB this will revert 
You could also try to use sudo
. This command allows you to execute commands as root. So when you want to edit the configuration files you could try:
sudo nano /etc/openhab/configurations/filename
Where you replace filename with the actual filename. When this works for you, changing the ownership doesn’t matter. And it is less of a security risk.
I can’t sudo to MATE using WinSCP, which means I can’t use an external editor, which means a headache 
Well, actually you can in WinSCP, just add the following line to /etc/sudoers (change username to your username, and yes this isn’t safe, but changing the ownership isn’t safe too
)
username ALL=NOPASSWD: /usr/lib/openssh/sftp-server
Then in the SFTP setup section of WinSCP edit the session SFTP server:
sudo /usr/lib/openssh/sftp-server
And you will have root access to your filesystem.
1 Like
My Pi, isn't externally accessible, so not too fussed about 'safety', and it only acts as my OpenHAB box.
When performing the above, I get;
Cannot initialize SFTP protocol. Is the host running a SFTP server?
