Linux_远程无密连接

客户端的连接方式

ssh 远程主机用户@远程主机ip
这里我的desktop主机 ip 为192.168.122.83
server ip 为 192.168.122.84

ssh root@192.168.122.84

接陌生主机时需要建立认证关系 所以需要输入该用户的密码
ssh 远程主机用户@远程主机ip -X 调用远程主机图形工具
ssh 远程主机用户@远程主机ip command 直接在远程主机运行某条命令
一、 sshkey 加密
1.生成公钥私钥

ssh-keygen   ##生成公匙私匙
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):[enter]     ##加密字符保存文件(建议用默认)
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):         [enter]     ##密钥密码,必须>4个字符   因为这里是需要无密码连接  所以我们不设置密码 直接回车
Enter same passphrase again:                [enter]     ##确认密码
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:                     
ab:3c:73:2e:c8:0b:75:c8:39:3a:46:a2:22:34:84:81 root@server0.example.com
The key's randomart image is:
+--[ RSA 2048]----+
|o                |
|E.               |
|..               |
|.  . o           |
|.o. * . S        |
|oo.o o   .       |
|+ =. .  .        |
|o. oo.+..        |
|    ..o*.        |
+-----------------+
[root@server0 ~]# ls /root/.ssh/
id_rsa  id_rsa.pub
id_rsa      ##私钥,就是钥匙
id_rsa.pub  ##公钥,就是锁

2.添加key认证方式

[root@server0 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub  root@192.168.122.83    
ssh-copy-id     ##添加key认证方式的工具
-i          ##指定加密key文件
/root/.ssh/id_rsa.pub   ##加密key
root            ##加密用户为root
192.168.122.83  ##被加密主机ip

3.分发钥匙给desktop主机

[root@server0 ~]# scp /root/.ssh/id_rsa root@192.168.122.84:/root/.ssh/

这里写图片描述

下面为效果图
这里写图片描述

4.提升openssh的安全级别

1.openssh-server配置文件

/etc/ssh/sshd_config
78 PasswordAuthentication yes|no        ##是否开启用户密码认证,yes为支持no为关闭
48 PermitRootLogin yes|no           ##是否允许超级用户登陆
49 AllowUsers student westos            ##用户白名单,只有在名单中出现的用户可以使用sshd建立shell
50 DenyUsers westos             ##用户黑名单

2.控制ssh客户端访问

vim /etc/hosts.deny
sshd:ALL        ##拒绝所有人链接sshd服务

vim /etc/hosts.allow
sshd:192.168.122.1  ##允许1主机链接sshd

sshd:192.168.122.1 , 192.168.122.83 ##允许1和83链接

sshd:ALL EXCEPT 192.168.122.84      ##只不允许84链接sshd

3.ssh登陆提示修改该

vim /etc/motd       ##显示登陆后字符

hello world     ##在登陆后就会显示这个字符
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值