当没有 .ssh 时,如何在没有密码的情况下通过 ssh 连接到服务器

how to ssh to a server without password when there is no .ssh on it

我想设置从我的本地机器无密码登录到这个 Linux 服务器。当我尝试上传我的 public 密钥时,我发现服务器上没有 .ssh。所以我在服务器上用 ssh-keygen 创建了一个。但是在新生成的.ssh 目录中,没有authorized_keys 或known_hosts。所以我制作了一个新的 authorized_keys 并从本地机器粘贴了我的 public 密钥。但是它不起作用,ssh 仍然需要密码。谁能告诉我我做对了吗?

这是 ssh -vvv 的输出:

debug1: Authentications that can continue: publickey,gssapi-with-mic,password,keyboard-interactive
debug3: start over, passed a different list publickey,gssapi-with-mic,password,keyboard-interactive
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup gssapi-with-mic
debug3: remaining preferred: publickey,keyboard-interactive,password
debug3: authmethod_is_enabled gssapi-with-mic
debug1: Next authentication method: gssapi-with-mic
debug3: Trying to reverse map address .
debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_198782' not found

debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_198782' not found

debug1: Unspecified GSS failure.  Minor code may provide more information


debug1: Unspecified GSS failure.  Minor code may provide more information
Credentials cache file '/tmp/krb5cc_198782' not found

debug2: we did not send a packet, disable method
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /rsrch2/rists/djiao/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug3: Wrote 368 bytes for a total of 1477
debug1: Authentications that can continue: publickey,gssapi-with-mic,password,keyboard-interactive
debug1: Trying private key: /rsrch2/rists/djiao/.ssh/id_dsa
debug3: no such identity: /rsrch2/rists/djiao/.ssh/id_dsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup keyboard-interactive
debug3: remaining preferred: password
debug3: authmethod_is_enabled keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug3: Wrote 96 bytes for a total of 1573
debug2: input_userauth_info_req
debug2: input_userauth_info_req: num_prompts 1

只需创建它并将您的密钥复制到其中即可。如果您有密钥复制工具,则只需通过

创建文件
$ touch ~/.ssh/authorized_keys

在使用该工具之前。

使用 -vvv 进行连接可能会有所帮助。

在客户端和服务器上,检查 ~/.ssh 是否具有权限 700。

在服务器上,检查 /etc/ssh/sshd_config 是否有:

AuthorizedKeysFile  .ssh/authorized_keys
PubkeyAuthentication yes
RSAAuthentication yes