建立信任关系失败

本文介绍了SSH免密登录常见的两种问题及解决方法。一种是权限问题,涉及.ssh目录和authorized_keys文件的权限设置;另一种是配置问题,涉及如何通过修改ssh_config文件来指定正确的私钥文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

情况一:权限问题:

现象:A建立与B的信任关系,但是建立失败

解决:查看B的用户下.ssh/authorized_keys的权限,只能是700,或者是644,不能是其他

 

情况二:关于ssh信任关系--每台主机指定不同的私钥文件
当主机与10.11.70.25创建了信任关系后,每次ssh远程登陆10.11.70.25时都要求输入密码,如下:
linux:/etc/ssh/# ssh 10.11.70.25
Authorized users only. All activity may be monitored and reported.
Password:

排查了/etc/ssh/sshd_config中
#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile      .ssh/authorized_keys
都是默认的yes。

补充说明:
OpenSSH 的服务端配置文件一般为 /etc/ssh/sshd_config,和公钥认证有关的两个配置项是:
#RSAAuthentication yes
#PubkeyAuthentication yes
其缺省值一般为 yes。如果希望仅打开公钥认证,禁用其他的认证方式,则可以修改下列配置项:
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no
上述配置项如果有任何需要修改的地方在修改之后重启ssh服务器让新的设置生效。

最后排查到ssh_config配置文件,内容如下:
linux:/etc/ssh/# cat /etc/ssh/ssh_config

# Site-wide defaults for some commonly used options.  For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.

Host *
#   ForwardAgent no
#   ForwardX11 no

# If you do not trust your remote host (or its administrator), you
# should not forward X11 connections to your local X11-display for
# security reasons: Someone stealing the authentification data on the
# remote side (the "spoofed" X-server by the remote sshd) can read your
# keystrokes as you type, just like any other X11 client could do.
# Set this to "no" here for global effect or in your own ~/.ssh/config
# file if you want to have the remote X11 authentification data to
# expire after two minutes after remote login.
ForwardX11Trusted yes

#   RhostsRSAAuthentication no
#   RSAAuthentication yes
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/identity
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   Port 22
    Protocol 2
#   Cipher 3des
#   Ciphers aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc
#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no

# Set this to 'yes' to enable support for the deprecated 'gssapi' authentication
# mechanism to OpenSSH 3.8p1. The newer 'gssapi-with-mic' mechanism is included
# in this release. The use of 'gssapi' is deprecated due to the presence of
# potential man-in-the-middle attacks, which 'gssapi-with-mic' is not susceptible to.
#   GSSAPIEnableMITMAttack no

# This enables sending locale enviroment variables LC_* LANG, see ssh_config(5).
SendEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
SendEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
SendEnv LC_IDENTIFICATION LC_ALL
IdentityFile ~/.ssh/identification

文件末尾多了一行IdentityFile的定义,重新定义了IdentityFile为~/.ssh/identification

说明:
当主机中有多个密钥对的情况下,可以通过设置 /etc/ssh/ssh_config中对不同的主机和用户使用不同的私钥文件。如下例:
Host *   
IdentityFile ~/.ssh/%r@%h

对所有主机使用私钥文件路径和名称格式为:~/.ssh/%r@%h

Host 10.11.70.25
IdentityFile ~/.ssh/id_dsa141
只对远程主机10.11.70.25进行ssh连接时,使用的私钥文件为~/.ssh/id_dsa141

而实际上我们的私钥文件还是使用的默认的~/.ssh/id_rsa
文件ssh_config中配置为了IdentityFile ~/.ssh/identification,导致远程登陆时私钥文件系统默认找identification,而不是id_rsa。
因此每次都需要重新输入密码。

修改方法:
删除掉或是注释掉最后一行:
#IdentityFile ~/.ssh/identification

修改后,文件配置文件是即时生效,无需重启ssh服务。
linux:~/.ssh # ssh 10.11.70.25
Authorized users only. All activity may be monitored and reported.
Last login: Thu Feb 20 15:23:10 2014 from 10.18.56.23
Authorized users only. All activity may be monitored and reported.
linux101:~ # ls

顺利登陆远程服务器10.11.70.25,问题解决。

### 如何修复 Windows 工作站和 Active Directory 主域之间的信任关系故障 #### 验证 DNS 设置 确保在客户端上配置的所有 DNS 服务器都正确托管目标域中域控制器(DC)所需的区域和有效的记录。常见的错误配置包括: - 缺少目标 AD 域的正向查找区域[^2]。 - 缺少 `_msdcs` 正向查找区域。 如果这些区域缺失,则需创建相应的DNS区域并添加必要的资源记录,特别是 LDAP SRV 和主机 A 记录。 #### 检查特定 DNS 资源记录的存在性和准确性 确认以下关键 DNS 资源记录是否存在且准确无误: - _msdcs.<林根域> 区域应包含目标域中 DC 的轻型目录访问协议(LDAP) SRV 记录。 - 目标 AD 域区域内的主机 A 记录应当指向正确的 IP 地址,并且该地址对应的网络接口可被客户端计算机访问。 对于任何发现的问题,更新或修正相应条目以确保其有效性。 #### 更新 Kerberos 票据授予票据(TGT) 当遇到与Kerberos认证有关的信任问题时,尝试刷新本地安全授权子系统服务(LSASS)缓存中的TGT: ```powershell klist purge ``` 此命令会清除当前用户的 TGT 并强制重新获取新的票证。 #### 使用 `netdom resetpwd` 或者 `nltest /reset` 来重置机器账户密码 这两种方法都可以用来重设工作站同AD主域间的信任关系: ```cmd netdom resetpwd /s:<DC_IP_Address> /ud:Administrator /pd:* ``` 或者, ```cmd nltest /server:<Domain_Name> /reset ``` 执行上述任一操作之后重启工作站使更改生效。 #### 手动删除并重新加入域 作为最后手段,在备份重要数据的前提下考虑卸载现有域名成员身份再重新加入指定的Active Directory域: 1. 断开现有的域连接; 2. 将电脑设置为工作组模式; 3. 重启设备; 4. 加入正确的域。 完成以上步骤后测试新建立起来的信任关系是否正常工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值