Python module learning-Paramiko-Use python to throw an exception: Authentication failed.

When an exception is thrown, paramiko. Ssh_exception. AuthenticationException: Authentication failed.
Please check:
1. Is port 22 enabled on the cloud server?
2. Is the password wrong when passing the parameter?

Error reporting example:


 
Operation method:
 
Take my Tencent Cloud as an example:
1. Click the security group rule to check whether the server opens port 22:

 
2. Check whether the code transmission parameter: account password is correct:

import paramiko

# 实例化SSHClient
client = paramiko.SSHClient()

# 自动添加策略,保存服务器的主机名和密钥信息,如果不添加,那么不再本地know_hosts文件中记录的主机将无法连接
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# 连接SSH服务端,以用户名和密码进行认证
client.connect(hostname='192.168.1.105', port=22, username='root', password='123456')

# 打开一个Channel并执行命令
stdin, stdout, stderr = client.exec_command('df -h ') # stdout 为正确输出,stderr为错误输出,同时是有1个变量有值

# 打印执行结果
print(stdout.read().decode('utf-8'))

# 关闭SSHClient
client.close()

 
3. After checking, run the Linux command with Python:

Read More: