meatball1982 发表于 2016-8-19 15:49:53

服务器之间的ssh ,无密码copy

转的。挺好用的。

http://blog.csdn.net/emili/article/details/3856622

如果想在 A 这太机器上可以不需要密码就 ssh 到 B 、 C 两台机器上,可以采用如下的方法:( 1 ) 在 A 机器上: ssh-keygen -t rsaGenerating public/private rsa key pair.
Enter file in which to save the key (/nutch/home/.ssh/id_rsa): 不输入任何东西,直接回车
Enter passphrase (empty for no passphrase): 不输入任何东西,直接回车
Enter same passphrase again: 不输入任何东西,直接回车
Your identification has been saved in /nutch/home/.ssh/id_rsa.
Your public key has been saved in /nutch/home/.ssh/id_rsa.pub.
The key fingerprint is:
40:b8:e9:8f:0a:f6:ce:e0:73:a8:6a:7e:52:b4:45:ca nutch@linux1这个命令将为 A 上的用户生成其密钥对,询问其保存路径时直接回车采用默认路径,当提示要为生成的密钥输入passphrase 的时候,直接回车,也就是将 其设定为空密码。生成的密钥对 id_rsa , id_rsa.pub ,默认存储在/home/username/.ssh 目录下。(2) 在 A 机器上:将 id_rsa.pub 的内容复制到 A 、 B 、 C 三台机器 /home/username/.ssh/authorized_keys 文件中,如果机器上已经有 authorized_keys 这个文件了,就在文件末尾加上 id_rsa.pub 中的内容,如果没有authorized_keys 这个文件,直接 cp 或者 scp 就好了,下面的操作假设各个机器上都没有 authorized_keys 文件。(如果 B 、 C 机器上没有 ~/.ssh 目录可以手动自己创建 , 权限要设置成可以写,因为要 copyauthorized_keys)对于 A : cp id_rsa.pub authorized_keys对于 B 和 C : scp authorized_keys username@B:~/.ssh/ 此处的 username 是要访问的 B 机器上的用户名。(3) chmod 644 authorized_keys
这一步非常关键,必须保证 authorized_keys 只对其所有者有读写权限,其他人不允许有写的权限,否则 SSH 是不会工作的(4) 可以直接 ssh username@ 机器名了,同一台机器的不同用户直接也可以以这种方式来访问


meatball1982 发表于 2016-8-22 19:42:49

chmod 644 authorized_keys

这一步,很重要。

meatball1982 发表于 2018-11-30 10:30:59

https://www.linuxdashen.com/ssh-key%EF%BC%9A%E4%B8%A4%E4%B8%AA%E7%AE%80%E5%8D%95%E6%AD%A5%E9%AA%A4%E5%AE%9E%E7%8E%B0ssh%E6%97%A0%E5%AF%86%E7%A0%81%E7%99%BB%E5%BD%95

meatball1982 发表于 2020-1-2 10:25:16

在mac下。
上述 完事


eval $(ssh-agent)
ssh-add

把密码也记住。

meatball1982 发表于 2020-8-14 15:28:14

ssh-keygen -t rsa
ssh-copy-id username@remote-server

其中,username是服务器上,你的用户名,
remote-server是服务器的ip
ssh-copy-idzhubajie@159.226.238.000

meatball1982 发表于 2024-4-22 11:22:53

当你没有root权限,需要自己定义一个ip地址。
可以通过如下的方式


vi ~/.ssh/config

Host Xitian
   User zhubajie
   Hostname 123.234.345.456


其中,
Xitian是你自定义的host name。
zhubajie是用户名,
123.234.345.456是ip
通过上面的帖子,可以不用密码


ssh Xitian

直接进。

meatball1982 发表于 4 天前

meatball1982 发表于 2024-4-22 11:22
当你没有root权限,需要自己定义一个ip地址。
可以通过如下的方式



还需要
chmod 600 ~/.ssh/config
页: [1]
查看完整版本: 服务器之间的ssh ,无密码copy