Introduction
If your Linux server/PC is equipped with an NVIDIA GPU and you need to adjust its fan speed via SSH without a graphical interface, this is the easiest method to achieve your goal. Whether you’re looking to reduce noise, enhance efficiency, or simply keep your hardware cool, this guide will help you get started quickly.
(No GUI Required,just need SSH)(Perhaps the simplest)
Script Address: https://github.com/RoversX/nvidia_fan_control_linux/
Blog Article: https://blog.closex.org/posts/26a7c6ee/
Quick Start Guide
Setting Up Your Environment
- Create a Python Virtual Environment
python3 -m venv fan
source fan/bin/activate
2. Install the pynvml
pip3 install pynvml
3. Download the Fan Control Script
wget https://raw.githubusercontent.com/RoversX/nvidia_fan_control_linux/main/nvidia_fan_control.py
4. Modify the script as needed
# Fan curve parameters
temperature_points = [0, 40, 57, 70]
fan_speed_points = [27, 40, 80, 100]
# Sleep interval to reduce CPU activity
sleep_seconds = 5
Configure the Script
Create a simple fan.sh
script to make the start-up process more convenient
nano fan.sh
In the editor that opens, copy and paste the following content:
#!/bin/bash
# Use sudo to elevate privileges and activate the virtual environment
sudo bash <<EOF
source /home/x/Workspace/fan/bin/activate
python /home/x/Workspace/fan/nvidia_fan_control.py
deactivate
EOF
Start the Fan Control
With everything set up, all you need to do is run the following command to start controlling the fan speed:
./fan.sh
Output Example
After running the script, you will see an output like this:
x@x:~$ ./fan.sh
[sudo] password for x:
============================================================
Driver Version: 535.183.01
GPU 0: NVIDIA GeForce RTX 2080 Ti
Fan Count: 1
============================================================
Temperature: 42°C
Total Curve Point: 4
Current Curve Point: 2
Previous_Curve_Point: 1
Fan_Speed: 45%
============================================================
Temperature_Delta: 17
Fan_Speed_Delta: 40
Temperature_Increment: 2
Fan_Speed_Increment: 4.705882352941177
Previous_Temperature: 42°C
Step_Down_Temperature: 37
============================================================
This output clearly shows the current temperature and fan speed of your GPU, ensuring your device operates under optimal conditions.
This script was improved based on: https://github.com/Cippo95/nvidia-fan-control
I also use some code from https://gist.github.com/AlexKordic/65f031b708177a01a002cc19f0d7298c to reset back to auto fan control.
finally:
# reset to auto fan control
for handle, fan_count in zip(handles, fan_counts):
for i in range(fan_count):
nvmlDeviceSetDefaultFanSpeed_v2(handle, i)
nvmlShutdown()
Conclusion
With these steps, you can easily control the fan speed of NVIDIA GPUs on Linux without the need for a graphical interface, making it particularly suitable for remote management and server environments.