在 scp 和 ssh 中使用 ssh 密钥 [英] using ssh keys with scp and ssh

查看:53
本文介绍了在 scp 和 ssh 中使用 ssh 密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 scp 将几个文件复制到目标系统,然后登录系统并安装这些文件.我在这里使用 scp 和 ssh 命令以及 ssh 密钥进行无密码身份验证.

I am trying to copy few files to a target system using scp and then login to the system and install those files. I used scp and ssh commands here with ssh keys for passwordless authentication.

ssh 密钥是在源系统上创建的,如下所示.这是创建 ssh 密钥的正确且安全的方式吗?

The ssh key was created on the source system as below. Is this the correct and secured way of creating an ssh key?

~]# ssh-keygen -t rsa -N "" -f ~/.ssh/mytest.key

通过执行以下命令将密钥从源系统复制到目标系统.

The key was copied from the source to target system with executing below command.

~]# ssh-copy-id -i ~/.ssh/mytest.key 

现在,SSH 登录工作正常,没有提示输入密码,但是 scp 仍然无法正常工作..它仍然提示输入密码.使用 scp 时应该指定密钥路径吗?如果是这样,我如何指定密钥路径和 scp 命令?

Now, the SSH login works fine without prompting for a password, however the scp is still not working.. it still prompts for a password. Should I specify the key path when using scp? If so how do I specify the keypath along with scp command?

这里是使用的ssh命令

Here is the ssh command used

~]# ssh -i ~/.ssh/mytest.key root@192.168.1.1

推荐答案

假设你的情况来自 192.168.1.1 的 scp 尝试下面的命令.

Assume your case for scp from 192.168.1.1 try below command.

scp -i ~/.ssh/mytest.key root@192.168.1.1:/<filepath on host>  <path on client>

确保密钥文件的权限为 600 或 400.

make sure the key file should have permission 600 or 400.

这篇关于在 scp 和 ssh 中使用 ssh 密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆