使用Linux SCP命令配合ssh密钥上传文件出错

当使用scp命令从本地往远程服务器上传文件时,并且使用ssh key作为密钥方式连接时。可能会出现这个错误.

比如用以下命令:

scp -i ./your_ssh_key.pem local_file_name username@remoteIP:/home/

运行后,出现报错:

The authenticity of host '111.111.111.111 (111.111.111.111)' can't be established.
ECDSA key fingerprint is SHA256:Qlo0h0LwJGZlATTzWvLKtsQojtOw/rF48cubdJqI6Us.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '111.111.111.111' (ECDSA) to the list of known hosts.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for './your_ssh_key.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "./your_ssh_key.pem": bad permissions
[email protected]: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
lost connection

出现这个错误主要是公钥的权限太大,把权限降为600即可,执行以下命令,修改密钥文件权限:

chmod 600 ./your_ssh_key.pem

再次运行,一切OK。

你可能感兴趣的:(linux,ssh,centos,shell)