Install SSH public key on remote host and execute bash command

For SSH monitoring it is recommended you to establish an passwordless connection between zabbix server and remote host. You have to log in into Zabbix server and install SSH key for user zabbix and distribute this key to each host. Here is the steps to implement this scenario:

Check existing setup:
grep "SSHKeyLocation=" /usr/local/etc/zabbix_server.conf
Enable SSHKeyLocation:
sed -i "s/^.*SSHKeyLocation=/SSHKeyLocation=\/home\/zabbix\/.ssh/" /usr/local/etc/zabbix_server.conf
Check again:
grep "SSHKeyLocation=" /usr/local/etc/zabbix_server.conf
Make directory for SSH keys
mkdir -p /home/zabbix/.ssh
Allow zabbix user to own the dir
chown -R zabbix:zabbix /home/zabbix
Restart Zabbix server service:
systemctl restart zabbix-server
Open /etc/passwd and make sure zabbix home dir has been set to /home/zabbix
zabbix:x:1001:1001::/home/zabbix:/usr/sbin/nologin
Generate the SSH key for user zabbix:
sudo -u zabbix ssh-keygen -t rsa -b 2048
This will ask for passphrase. You can enter none

Copy key to remote host:
sudo -u zabbix ssh-copy-id pi@ip.address.goes.here -p 22
Note that SSH key will be installed only on user in this command ('root' in my example) Move to user zabbix to test the connection:
su -s /bin/bash zabbix
Test the login:
ssh -p '22' 'pi@ip.address.goes.here'
Note that now the authorization is passwordless

Exit SSH session. Exit user zabbix session

Now on the fronend I can create a key: