当前位置: 首页 > news >正文

ssh 故障排查和免密登陆

ssh 故障

你是某金融科技公司的 Linux 运维工程师,负责维护核心生产服务器集群。

发现某台服务器无法通过ssh远程登录。

请排查故障,并修复问题。

故障模拟

server设置

[root@server ~ 11:38:53]# usermod -s /sbin/nologin zhangsan
[root@server ~ 11:44:22]# echo 123 | passwd --stdin zhangsan
更改用户 zhangsan 的密码 。
passwd:所有的身份验证令牌已经成功更新。
[root@server ~ 11:44:43]# systemctl stop sshd

client设置

[dyx@client ~ 10:52:07]$ chmod 666 .ssh/config
[dyx@client ~ 11:45:20]$ cat > .ssh/config <<EOF
> Host *
>   User zhangsan
>   StrictHostKeyChecking yes
> EOF
[dyx@client ~ 11:45:55]$ > .ssh/known_hosts

排故故障

  1. 错误现象:
[dyx@client ~ 11:46:10]$ ssh server
Bad owner or permissions on /home/dyx/.ssh/config
  1. 处理方法:
[dyx@client ~ 11:48:05]$ ll .ssh/config
-rw-rw-rw- 1 dyx dyx 51 915 11:45 .ssh/config
[dyx@client ~ 11:48:23]$ chmod 600 .ssh/config
[dyx@client ~ 11:48:36]$ ll .ssh/config
-rw------- 1 dyx dyx 51 915 11:45 .ssh/config
  1. 错误现象:
[dyx@client ~ 11:48:39]$ ssh server
ssh: connect to host server port 22: Connection refused
  1. 处理方法:
[root@server ~ 11:44:53]# systemctl status sshd
● sshd.service - OpenSSH server daemonLoaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)Active: inactive (dead) since 一 2025-09-15 11:44:53 CST; 5min agoDocs: man:sshd(8)man:sshd_config(5)Process: 2059 ExecStart=/usr/sbin/sshd -D $OPTIONS (code=exited, status=0/SUCCESS)Main PID: 2059 (code=exited, status=0/SUCCESS)[root@server ~ 11:50:00]# systemctl start sshd[root@server ~ 11:50:21]# systemctl status sshd
● sshd.service - OpenSSH server daemonLoaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)Active: active (running) since 一 2025-09-15 11:50:21 CST; 3s agoDocs: man:sshd(8)man:sshd_config(5)Main PID: 2086 (sshd)CGroup: /system.slice/sshd.service└─2086 /usr/sbin/sshd -D
  1. 错误现象:
[dyx@client ~ 11:49:30]$ ssh server
No ECDSA host key is known for server and you have requested strict checking.
Host key verification failed.
  1. 处理方法:
[dyx@client ~ 11:50:46]$ vim .ssh/config
[dyx@client ~ 12:31:20]$ cat .ssh/config
Host *User zhangsanStrictHostKeyChecking no
  1. 错误现象:
[dyx@client ~ 12:31:24]$ ssh server
Warning: Permanently added 'server,10.1.8.10' (ECDSA) to the list of known hosts.
zhangsan@server's password: 
Last failed login: Mon Sep 15 10:34:32 CST 2025 from client.dyx.cloud on ssh:notty
There were 2 failed login attempts since the last successful login.
This account is currently not available.
Connection to server closed.
  1. 处理方法:
[root@server ~ 11:50:25]# cat /etc/passwd | grep zhangsan
zhangsan:x:1001:1001::/home/zhangsan:/sbin/nologin
[root@server ~ 12:32:06]# usermod -s /bin/bash zhangsan

处理结果

[dyx@client ~ 12:31:40]$ ssh server
zhangsan@server's password: 
Last login: Mon Sep 15 12:31:40 2025 from client.dyx.cloud

免密登陆

[dyx@client ~ 12:33:31]$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/home/dyx/.ssh/id_rsa): 
/home/dyx/.ssh/id_rsa already exists.
Overwrite (y/n)? 
[dyx@client ~ 12:33:47]$ ssh-copy-id zhangsan@server
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/dyx/.ssh/id_rsa.pub"
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
zhangsan@server's password: Number of key(s) added: 1Now try logging into the machine, with:   "ssh 'zhangsan@server'"
and check to make sure that only the key(s) you wanted were added.[dyx@client ~ 12:34:04]$ ssh server
Last login: Mon Sep 15 12:32:56 2025 from client.dyx.cloud
[zhangsan@server ~ 12:34:10]$ 

文章转载自:

http://10h1dYxc.ghwtn.cn
http://xV6vZrsu.ghwtn.cn
http://8mUqlavB.ghwtn.cn
http://xoNhbfhX.ghwtn.cn
http://SuXoZupG.ghwtn.cn
http://OCquil7g.ghwtn.cn
http://VQriNhCr.ghwtn.cn
http://u7cYtZSb.ghwtn.cn
http://FdIp6kJ5.ghwtn.cn
http://7qxHOwSg.ghwtn.cn
http://KQUmdzRT.ghwtn.cn
http://IcqL0Yxt.ghwtn.cn
http://Hlh2ywww.ghwtn.cn
http://EEflGSLn.ghwtn.cn
http://nr41LhBv.ghwtn.cn
http://qkdcizWh.ghwtn.cn
http://9W4nLKbE.ghwtn.cn
http://ZKNcBlwj.ghwtn.cn
http://yYcxbpLN.ghwtn.cn
http://zx6hSPGT.ghwtn.cn
http://7CvEgabz.ghwtn.cn
http://41sthM6Z.ghwtn.cn
http://6dbmBgxI.ghwtn.cn
http://MXaWEjhY.ghwtn.cn
http://HB0imM7N.ghwtn.cn
http://BNwwLRk9.ghwtn.cn
http://PqtfIMmd.ghwtn.cn
http://h26zK8yz.ghwtn.cn
http://jLMQz1QP.ghwtn.cn
http://705DaGCA.ghwtn.cn
http://www.dtcms.com/a/385068.html

相关文章:

  • exists和in的区别及适用场景
  • 基于单片机的客车综合报警系统(论文+源码)
  • 积极践行“人工智能+”行动,山东大学数字人文教科研一体平台完成 AI 化升级
  • 晨曦中,它已劳作:一台有温度的机器人如何重塑我们的洁净日常
  • 易语言中判断函数中可空参数不为空?
  • 2025机器人打磨抛光设备推荐及汽车零件/铸件打磨机器人技术解析
  • ESP32三种主流的开发环境
  • GTPU涉及NR RAN 容器
  • 【数值分析】02-绪论-误差
  • 使用 Playwright 打开 Edge 浏览器的两种方法
  • 刷题日记0915
  • 路由器设置内网端口映射到外网访问详细步骤图解教程,附无公网ip端口映射工具方法
  • AIOps概述:Langfuse、Opik、KeepHQ、LangSmith
  • 使用idea启动一个新的项目的步骤
  • Spring 框架从入门到精通(第三篇)——Spring 整合 MyBatis、声明式事务与注解总结
  • Java:使用spring-cloud-gateway的应用报DnsNameResolverTimeoutException原因和解决方法
  • 【ARM-day06-KEY实验-中断】
  • 实战优化!多智能体React模式:层级指挥的黄金法则​
  • 容器逃逸漏洞
  • 石头科技出海升级:全球电商业财一体化与OMS实践
  • (二)文件管理-文件权限-chmod命令的使用
  • 使用 cAdvisor 监控容器
  • MongoDB 删除集合
  • 【C++】C++中内存管理的利器“智能指针”
  • C++——高并发内存池设计(一)
  • 快速入门HarmonyOS应用开发(一)
  • 深入解析 `pthread_detach`:告别线程的优雅之道
  • Arduino 通讯接口全景解析:从硬件到软件的跨板对话艺术
  • Python3练习题
  • AI GEO 实战:借百度文小言优化,让企业名称成搜索热词