me小怪兽

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

scp实现免密拷贝

scp免密码登陆(设置SSH密钥)
服务器A需要传输文件至B:即A生成密钥,B保存密钥
A_ip:192.168.61.114
B_ip:192.168.61.116

1、A服务器执行
复制代码
[root@nginx ~]# ssh-keygen  #生产公钥和私钥,一路回车
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:UB3AQ0pZ1UP/kZUL5YYRm2ND4Wv3dGS+wUFoRBIPv0Y root@nginx
The key's randomart image is:
+---[RSA 2048]----+
| .==+oB=B=oo|
| ..oo . X=B.o|
| o . .Eo*+|
| . o B*o|
| S = +=|
| o ..=|
| ..|
| |
| |
+----[SHA256]-----+
复制代码
2、A服务器执行
复制代码
[root@nginx ~]# ssh-copy-id 192.168.61.116 -p19880 #将A密钥拷贝到B
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '[192.168.61.116]:19880 ([192.168.61.116]:19880)' can't be established.
ECDSA key fingerprint is SHA256:vzoV5jlVZ8X5GV/SIStmV0j0ua22W16mUotMaqBBhqE.
ECDSA key fingerprint is MD5:37:ea:d2:fb:36:6f:1d:49:54:b6:6e:3c:49:86:38:04.
Are you sure you want to continue connecting (yes/no)? yes #yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@192.168.61.116's password: #输入B的密码

Number of key(s) added: 1

Now try logging into the machine, with: "ssh -p '19880' '192.168.61.116'" #配置完成
and check to make sure that only the key(s) you wanted were added.
复制代码
3、测试
[root@nginx ~]# scp -P19880 copy.yml 192.168.61.116:/opt
copy.yml 100% 494 429.8KB/s 00:00
[root@nginx ~]#

注:秘钥文件默认在用户的家目录下

[root@nginx .ssh]# cd /root/.ssh/
[root@nginx .ssh]# ls
id_rsa id_rsa.pub known_hosts

id_rsa 私钥
id_rsa.pub 公钥
known_hosts 谁登陆过我的记录

密钥推给谁,我登录谁就不需要输密码了。

posted on   me小怪兽  阅读(449)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示