首页 > 其他分享 >scp实现免密拷贝

scp实现免密拷贝

时间:2022-11-21 10:22:05浏览次数:40  
标签:免密 rsa 192.168 id ssh key 拷贝 root 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
[email protected]'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 谁登陆过我的记录

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

标签:免密,rsa,192.168,id,ssh,key,拷贝,root,scp
From: https://www.cnblogs.com/xgsh/p/16910535.html

相关文章

  • python中的拷贝问题
    分为:赋值、浅拷贝、深拷贝deepcopy需要导入copy模块    而numpy中的解释不一样:https://www.numpy.org.cn/user/quickstart.html#%E5%AE%8C%E5%85%A8%E4%B8%8D......
  • shell expect免密函数块sftp、scp、ssh
    一、expect编写函数1、变量设置#!/bin/bash################remoteinfomation############remoteuser=zhangsanremotepass=123456remoteport=22remoteip=ip.txtremoteconfi......
  • Java IO 中常用的目录和文件操作,用到的时候从这里拷贝就行了
    文件是操作系统对磁盘上数据的组织形式。文件包括文件路径和文件名,比如:/Users/Calvin/Desktop/demo.txt复制代码文件名的后缀其实是文件名的一部分,文件不一定要有后缀,但是一......
  • 75:浅拷贝和深拷贝_内存分析
    ###浅拷贝和深拷贝为了更深入的了解参数传递的底层原理,我们需要讲解一下“浅拷贝和深拷贝”。我们可以使用内置函数:copy(浅拷贝)、deepcopy(深拷贝)。浅拷贝:不拷贝子对象......
  • 深拷贝和浅拷贝
    常见浅拷贝的方式:Object.assign()、扩展运算符常见深拷贝的方式:JSON.parse()和JSON.stringify()配合使用浅拷贝只复制一层对象属性深拷贝递归复制所有层    ......
  • 服务器之间建立互信,免密登录SSH
    生成SSHKEY[root@kafaka3~]#cd/root/.ssh[[email protected]]#pwd/root/.ssh[[email protected]]#ssh-keygen #生成秘钥Generatingpublic/privatersakeypair......
  • 35:列表_元素删除的三种方式_删除本质是数组元素拷贝
    ###列表元素的删除###del删除删除列表指定位置的元素。>>>a=[100,200,888,300,400]>>>dela[1]>>>a[100,200,300,400]###pop()方法pop()删除并返回指定位置......
  • 【学习笔记】Python深浅copy拷贝解析
    一、列表的赋值(一般用于读操作)这个和列表的深浅拷贝其实没有关系,就是一个赋值操作;list1和list2指向的是同一片内存地址;即,你家有套房子,叫清华楼A栋101室,也叫......
  • vb中filecopy拷贝文件
    FileCopy("源文件名","目标文件名")两个参数都是必选的,且都包含路径。在VB中filecopy函数可以直接调用。而CopyFile函数则不能要先定义......
  • weblogic免密登录使用nohup启动密码无效问题
    目录weblogic免密登录使用nohup启动密码无效问题1、密码重置1.1、使用一下命令可以重置weblogic的密码,注意后面有一个点,前面还有一个空格1.2、将生成的文件DefaultAuthenti......