Linux中的远程登录服务


一、Openssh的功能

1.sshd服务的用途
作用:可以实现通过网络在远程主机中开启shell服务
Secure SHell ===>ssh ##客户端
Secure SHell daemon ===> ##服务端
2.安装包
openssh-server
3.主配置文件
/etc/ssh/sshd_conf
4.默认端口
22
5.客户端命令
ssh

二、ssh

ssh [-l 远程主机用户] <ip|hostname>

ssh -l root 172.25.254.140 ##通过ssh命令在140主机中以root身份开启shell
[westos@linux_ccc ~]$ ssh -l root 172.25.254.170
The authenticity of host '172.25.254.170(172.25.254.170)'can't be established.
ECDSA key fingerprient is SHA256:luLJ3EuYztl6BRTdRgDBJOY6wxCZcfppTLSwTLSwTI3BuCs.
Are  you sure you wang to continue connecting (yes/no/[fingerprint])? yes    #身份证明生成过程确认

#作用#
当收入<yes>后  170主机会向当前主机发送身份公钥,并保存此公钥到~/.ssh/know_hosts
170主机持有私钥当客户主机再次连接时会对客户主机进行身份验证

当连接因为认证问题被拒绝时解决方案

vim ~/.ssh/konw_hosts  #在此文件中删除报错提示相应的行即可

ssh 常用参数
-l #指定登陆用户
-i #指定私钥
-x #开启图形
-f #后台运行
-o #指定连接参数

#ssh -l root 172.25.254.140 “StrictHostKeyChecking=no” 首次连接不需要输入yes

-t #指定连接跳板

#ssh -l root 170.25.254.170 -t ssh -l root 172.25.254.170

三、sshd key认证

1、认证类型

1).对称加密
加密和解密是同一串字符
容易泄漏
可暴力破解
容易遗忘

2).非对称加密
加密用公钥,解密用私钥
不会被盗用
攻击者无法通过无密钥方式登陆服务器

2、生成非对称加密密钥

方法一:

$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):         #输入保存密钥文件
Enterpassphrase (empty for no passphrase):                    #确认密码
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:0ZV0K9g6NyZsaUIfbZMrfAGB31GQsJ3Fyvi04/psVSg root@localhost.localdomain
The key is randomart image is :
+---[RSA 3027]----+
|     .o..=0      |
|   .   +00..     |
|     .o+o++      |
|      E==*..     |
|   .  ooS.o      |
|  .  + =o*       |
|   . %+*         |
|    =+B..        |
|   .=+.          |
+----[SHA256]-----+

方法二

$ssh-keygen -f  /root/.ssh/id_rsa -p ""

3、对服务器加密

ssh-copy-id -i /root/.ssh/id_rsa.pub   username@serverip
ssh-copy-id -id /root/.ssh/id_rsa.pub   lee@172.25.254.105

测试

ssh westosa@172.25.254.170   #登录用户westosa不需要输入密码

四、sshd安全优化参数详解

setenforce 0
systemctl disable --now firewalld

Port 2222                     #设定端口为2222
PermitRootLogin yes|no        #对超级用户登陆是否禁止
PasswordAuthentication yes|no    #是否开启原始谜面认证方式
AllowUsers  westosa           #用户白名单
DenyUsers   westosb           #用户黑名单
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值