on  it road.com

故障排除

如果我们已按照上面给出的步骤操作,但仍提示我们输入密码,请按照下面给出的步骤(列表)来解决问题。

  1. 在 vi 命令模式下使用“set list”查看时,该密钥必须作为单个不间断行出现在authorized_keys 文件中。
    在 vi 的“设置列表”模式下查看键字符串时,回车将显示为“$”字符。
    如果密钥格式不正确,我们可以编辑包含密钥的行。

  2. 如果我们收到密码提示,请检查 /export/home 的权限(假设主目录为 /export/home/[userid])是否为 755 且全局可读。
    此权限设置是必要的,因为在读取 $HOME/.ssh/authorized_keys 文件之前,sshd 远程主机必须将登录 id 设置为 seteuid。
    为此, /export/home 需要是世界可读的。

  3. 文件 $HOME/.ssh/authorized_keys 是全局可写的,如下面的用户“user01”所示:

$ pwd
/export/home/user01/.ssh 
$ ls -la 
total 14 
drwxrwxrwx 2 user01 staff 512 Jun 11 15:41 . 
drwxrwxrwx 4 user01 staff 512 Jun 11 15:14 .. 
-rwxrwxrwx 1 user01 other 223 Jun 11 14:06 authorized_keys 
-rw-r--r-- 1 user01 user01 24 Jun 11 15:14 config 
-rw------- 1 user01 other 951 Jun 11 15:35 id_rsa 
-rw-r--r-- 1 user01 other 228 Jun 11 15:35 id_rsa.pub 
-rw-r--r-- 1 user01 other 231 Jun 11 15:47 known_hosts

要覆盖此行为,请将 /etc/ssh/sshd_config 文件“StrictModes”条目从“yes”(默认)编辑为“no”:

# grep StrictModes /etc/ssh/sshd_config 
StrictModes yes

在此之后重新启动 sshd 服务。

对于 Solaris 9

# /etc/init.d/ssh stop 
# /etc/init.d/ssh start

对于 Solaris 10

# svcadm refresh ssh
  1. 如果以下参数的任何默认设置 (YES) 已更改为“NO”,我们可能需要检查文件 /etc/ssh/sshd_config。
- PubkeyAuthentication
- RSAAuthentication
  1. 最后一步是调试 ssh 会话。
    这将有助于跟踪连接流并显示失败的位置。
    查找字符串:“下一个身份验证方法:publickey”。
# ssh -v -v -v user@hostname

配置无密码 ssh

要将 SSH 配置为使用 id_rsa 密钥登录,请执行以下步骤。

1.在客户端机器(本地主机)上生成私钥和公钥对。

# ssh-keygen -t rsa

ssh-keygen 将需要密钥类型 (-t)。
从 ssh-keygen 的手册页:

-t type              Specifies the algorithm  used  for  the key, where type is one of rsa, dsa, and rsa1.
  1. 这将在触发命令的用户的 $HOME/.ssh/* 下创建两个新文件(公共和私有 RSA 密钥)。
id_rsa ( Private Key)
id_rsa.pub ( Public Key)
  1. 生成 RSA 密钥后,我们需要复制公钥 (id_rsa.pub) 并将密钥添加到远程主机上用户主目录中的 $HOME/.ssh/authorized_keys 文件中。
    例如 root 使用 ssh 或者 scp 将文件传输到远程用户:
# cat ~/.ssh/id_rsa.pub | ssh remotehost 'cat >>~/.ssh/authorized_keys && echo "Host Key Copied"'

-或者

# scp $HOME/.ssh/id_rsa.pub remotehost:$HOME/.ssh/id_rsa.pub.copy
  1. 通过在没有密码的情况下登录远程系统来验证是否一切正常。
    我们还可以在远程主机的authorized_keys 文件中查看公共RSA 密钥。
# ssh remotehost
# cd $HOME/.ssh
# cat authorized_keys
如何在 Solaris 中配置无密码 ssh

该帖子详细介绍了使用 RSA 公钥身份验证配置无密码 ssh 的步骤,换句话说:使用公钥进行无密码登录。
此过程用于减少使用 Sun Secure Shell (SSH) 进行安全远程登录所需的登录提示数量,这还包括 SCP(安全复制)和 SFTP(安全文件传输)。

日期:2020-09-17 00:15:06 来源:oir作者:oir