簡體   English   中英

Python命令重啟linux服務失敗

[英]Python command fails to restart linux service

我的windows 機器上有這個python代碼,它獲取我的linux 服務器上的服務狀態:

import paramiko

client = paramiko.client.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect('MY_HOST', username='MY_USER', password='MY_PASS')

stdin, stdout, _stderr = client.exec_command('systemctl status example.service')

print(_stdout.read())

client.close()

但是當我從“systemctl status”切換到“systemctl restart”重新啟動服務時,什么也沒有發生,服務也沒有重新啟動!

做錯了什么嗎? 還有另一種方法可以在我的 windows 機器上使用 python 代碼重新啟動 linux 服務嗎? 提前致謝!

我找到了解決方案,問題是我沒有使用root用戶登錄,所以我將ssh配置更改為直接使用root用戶登錄,重啟成功!

1 - 首先,通過運行此命令“ sudo passwd root ”啟用 ROOT,然后輸入密碼並確認!

2 - 現在,讓我們使用此命令“ vi /etc/ssh/sshd_config ”編輯將在 Ubuntu 中啟用 SSH 訪問的文件!

3 - 查找這部分代碼並將其保留如下:

# Authentication:
LoginGraceTime 120
#PermitRootLogin prohibit-password
PermitRootLogin yes
StrictModes yes

4 - 最后使用此命令“ sudo systemctl restart ssh ”重新啟動 SSHD 服務,就是這樣!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM