SSH 免密码登录

每次登录远程服务器都要输密码!!!

这里写图片描述

事前准备

  • 本地机器:local

  • 远程机器:remote

实操步骤

  • 本地机器生成公钥,私钥: ssh-keygen -t rsa
fengyuruhui$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/chenshan/.ssh/id_rsa): /Users/chenshan/.ssh/id_rsa_test
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/chenshan/.ssh/id_rsa_test.
Your public key has been saved in /Users/chenshan/.ssh/id_rsa_test.pub.
The key fingerprint is:
SHA256:gYV/PFrA08nktGUZ8LlFJ/Fhg7wDRjYQslmwf4UYJZc taotao@mac007
The key's randomart image is:
+---[RSA 2048]----+
|       =oXOO*o==.|
|      .oXoXE+=.+o|
|      .=.=+.+.o .|
|        o.= .=   |
|        S= o. .  |
|        . .      |
|                 |
|                 |
|                 |
+----[SHA256]-----+
fengyuruhui$ ls ~/.ssh/ | grep test
id_rsa_test
id_rsa_test.pub
  • 上传本地公钥到远程机器: scp ~/.ssh/id_rsa_test.pub username@remote:.ssh/id_rsa_test.pub
fengyuruhui$  scp ~/.ssh/id_rsa_test.pub username@remote:.ssh/id_rsa_test.pub
username@remote's password:
id_rsa_test.pub 
  • 在远程机器上设置 authorized_keys : cat /root/.ssh/id_rsa_test.pub >> /root/.ssh/authorized_keys
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值