ssh 异常问题汇总

1、服务密码或ip变更导致的错误

[root@hadoop03 ~]# ssh hadoop01
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:adqH907amvyYtAc7evqtYRcH/9Aovmz3sgY9Go6dmho.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:2
ECDSA host key for hadoop01 has changed and you have requested strict checking.
Host key verification failed.

解决方法:

        编辑文件/root/.ssh/known_hosts ,注释掉hadoop01行,保存退出。重新执行 ssh  hadoop01命令,按提示录入密码即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当使用 Paramiko 库在 Python 中进行 SSH 连接时,可以通过设置 SSH banner 来显示自定义的欢迎信息。在设置 SSH banner 时,可能会出现异常,例如无法连接远程服务器或无法读取 SSH banner 等。为了避免这些异常导致程序崩溃,可以使用 Python 的异常处理机制来捕获并处理这些异常。 以下是一个捕获 SSH banner 异常的示例代码: ```python import paramiko hostname = 'example.com' port = 22 username = 'username' password = 'password' try: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname, port, username, password) transport = ssh.get_transport() transport.set_banner('Welcome to my SSH server!') except paramiko.AuthenticationException as auth_error: print(f'Authentication failed: {auth_error}') except paramiko.SSHException as ssh_error: print(f'SSH error: {ssh_error}') except Exception as e: print(f'Error: {e}') finally: ssh.close() ``` 在这个示例中,我们使用 try-except-finally 语句块来捕获可能出现的异常。如果出现认证异常(如用户名或密码错误),我们会捕获 AuthenticationException 异常;如果出现 SSH 异常(如无法连接远程服务器或无法读取 SSH banner),我们会捕获 SSHException 异常;如果出现其他类型的异常,则会捕获 Exception 异常。在 finally 代码块中,我们关闭 SSH 连接以释放资源。 通过使用异常处理机制,我们可以更好地控制程序的流程,避免程序崩溃或出现其他意外行为。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值