If using monitor attached to intel graphics of ssh try this command. This worked for me with Xubuntu 18.04 and nvidia 390 drivers.
sudo nvidia-xconfig -a --cool-bits=31 --allow-empty-initial-configuration
sudo systemctl restart lightdm.service
sudo DISPLAY=:0 XAUTHORITY=/var/run/lightdm/root/:0 nvidia-settings -a 'GPUFanControlState=1' -a 'GPUTargetFanSpeed=100'
This changes fan to 100% but over clock works the same way.
I found the answer here.
https://www.linuxquestions.org/questions/linux-general-1/how-to-run-nvidia-settings-remotely-4175599391/