Linux中客户端设置免密登陆远程服务端

实现方式:公私钥对
这里设服务端IP地址为:192.164.124.3

1、使用ssh-keygen命令在当前用户根目录下的.ssh目中中生成公钥~/.ssh/id_rsa.pub及私钥~/.ssh/is_rsa也可以使用ssh-keygen -t dsa或者直接用ssh-keygen,另外私钥的权限应当为600,公钥为644.【客户端操作】

[root@hsc ~]# ssh-keygen -t rsa
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:TI4EMq02oOpRjsrhD4yJ7pea4Idf8rtxrLSrvGIplhc root@hsc.example.com
The key's randomart image is:
+---[RSA 2048]----+
|  o..            |
|.  o..           |
|.. .  . .        |
|. +. . =         |
|..+.  . S        |
|== E  .          |
|Xo*.o+ o         |
|*@+== =          |
|=*O*oB+          |
+----[SHA256]-----+

2、将公钥拷贝到目标服务端系统【也在客户端操作就行】ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.164.124.3,这里也可以使用文件拷贝的指令scp,这个指令输入后需要密码scp ~/.ssh/id_rsa.pub root@192.164.124.3:~/.ssh/authorized_keys

[root@hsc ~]# ssh-copy-id root@192.164.124.3
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/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.164.124.3's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.164.124.3'"
and check to make sure that only the key(s) you wanted were added.

3、免密登陆服务端功能实现

[root@hsc ~]# ssh 192.164.124.3
Last login: Wed Aug  7 00:28:14 2019 from 192-164-124-112.hdsl.highway.telekom.at
[root@villainc ~]# 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值