我已使用以下 URL 的教程中提供的步骤设置 ssh,无需密码即可登录远程服务器: SSH 无密码登录。
当我尝试仅使用 ssh 命令登录服务器时:
$ ssh [email protected]
它工作正常,我可以在不输入密码的情况下登录,但是当我尝试使用 scp 命令将文件从本地复制到远程服务器时:
$ scp /location/to/file/localserver user@server:location/whereto/copy
它要求我输入密码,这很奇怪!
我还确保所有文件夹都具有正确的权限,如上面 URL 中所述。
有谁知道如何解决这个问题?
Executing: program /usr/bin/ssh host *.*.*.*, user ssadmin, command scp -v -t /home/ssadmin/nexthink_log`
OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013`
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to *.*.*.* [*.*.*.*] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_4.3
debug1: match: OpenSSH_4.3 pat OpenSSH_4* compat 0x00000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: kex: diffie-hellman-group-exchange-sha1 need=16 dh_need=16
debug1: kex: diffie-hellman-group-exchange-sha1 need=16 dh_need=16
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA **:**:**:**:**:**:**:**:**:**:**:**:**:**
debug1: Host '*.*.*.*' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-with-mic,password
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:0)
debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available (default cache: KEYRING:persistent:0)
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Next authentication method: password
ssadmin@*.*.*.*'s password:
答案1
首先登录您的 Linux 电脑并使用以下命令生成一对公钥。
$ ssh-keygen -t rsa
当它要求输入密码时,只需按 Enter 键。
在您的服务器用户中创建一个 .ssh 文件夹,并在其中将新生成的公钥 (id_rsa.pub) 上传到您的 PC 上用户的 .ssh 目录下,文件名为authorized_keys。
设置权限:
$ ssh [email protected] "chmod 700 .ssh; chmod 640 .ssh/authorized_keys"
就是这样!
安全无密码登录。
答案2
您可以使用ssh-copy-id
命令
$ ssh-copy-id 用户@主机名
这只会将您的本地密钥添加到authorized_keys
远程服务器中的文件中。确保您能够通过在sshd_config
文件中启用授权密钥来使用它。这样,无论是在 中ssh
还是在 中,都不会提示您输入密码scp
。
答案3
当您输入密码时,安全副本会起作用吗?
如果您的权限被拒绝,则可能只是您尝试复制到的位置不允许远程用户写入。