In my application I have two servers (private and external) and there is a need for the private server to run a script on the external server at a very high frequency.
To allow this high frequency throughput, I am using
ControlMaster to open a persistent ssh connection (without it the external server crashes because of high cpu load as a result of dealing with the authentication).
This is the ssh configuration:
Host <external_host_ip> ControlMaster auto ControlPath ~/.ssh/cm_socket/%r@%h:%p ControlPersist 600 User user1 IdentityFile ~/key.pem
This configuration worked for 'user1' user. Unfortunately, it didn't work for me for the 'www-data' user.
Assuming that the root folder for www-data is /var/www, I added the folder cm_socket there, and when I test the connection, I see that something happens there:
$ ll /var/www/.ssh/cm_socket/ srw------- 1 www-data www-data 0 Oct 19 08:49 user1@host_ip:22=
However, it caused apache to crash, and the only thing that help was restarting apache.
/var/www should be the root of www-data:
$ cat /etc/passwd | grep www www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
This is the /var/www/.ssh/config:
Host <external_host_ip> ControlMaster auto ControlPath ~/.ssh/cm_socket/%r@%h:%p ControlPersist yes User user1 IdentityFile /home/user1/key_wwwdata.pem
content and permissions of /var/www/.ssh:
$ ll /var/www/.ssh/ drwxr-xr-x 2 www-data www-data 4096 Oct 19 08:49 cm_socket/ -rw-r--r-- 1 www-data www-data 198 Oct 19 08:44 config
permission of the key file:
$ ll /home/user1/key_wwwdata.pem -rw------- 1 www-data www-data 1675 Oct 18 09:11 /home/user1/key_wwwdata.pem
Is there a way to make this solution work for all users (including www-data)?