是的,Ubuntu上的Mosquitto MQTT代理支持SSL/TLS加密
要在Ubuntu Mosquitto中啟用SSL/TLS加密,您需要按照以下步驟操作:
sudo apt-get update
sudo apt-get install mosquitto mosquitto-clients openssl
mkdir certs
cd certs
openssl req -new -x509 -days 365 -extensions v3_ca -keyout ca.key -out ca.crt
openssl genrsa -out server.key 2048
openssl req -new -out server.csr -key server.key
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 365
openssl genrsa -out client.key 2048
openssl req -new -out client.csr -key client.key
openssl x509 -req -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt -days 365
sudo cp ca.crt server.crt server.key /etc/mosquitto/certs/
/etc/mosquitto/mosquitto.conf
),添加以下內容以啟用SSL/TLS加密:listener 8883
cafile /etc/mosquitto/certs/ca.crt
certfile /etc/mosquitto/certs/server.crt
keyfile /etc/mosquitto/certs/server.key
require_certificate true
sudo systemctl restart mosquitto
現在,您的Mosquitto服務器已啟用SSL/TLS加密。客戶端可以使用以下命令連接到服務器:
mosquitto_pub -h <your_server_ip> -p 8883 -t "topic" -m "message" --cafile ca.crt --cert client.crt --key client.key
mosquitto_sub -h <your_server_ip> -p 8883 -t "topic" --cafile ca.crt --cert client.crt --key client.key
請確保將<your_server_ip>
替換為您的Mosquitto服務器的IP地址。