Linux系統的遠端登陸管理

doudou_51052054發表於2020-10-22

一、Openssh的功能

1、sshd服務的用途
#作用
#可以實現通過網路在遠端主機中開啟安全shell的操作
Secure SHell ====》ssh #客戶端
Secure SHell daemom ==》#服務端
2、安裝包: openssh-server
3、主配置檔案: /etc/ssh/sshd_conf
4、預設埠:22
5、客戶端命令: ssh

二、ssh

命令功能
ssh [-l 遠端主機使用者] <ip/hostname>
ssh -l root 172.25.254.4通過ssh命令在4主機中以root身份開啟遠端shell

在這裡插入圖片描述

作用

當輸入後,主機會向當前主機傳送身份公鑰,並儲存此公鑰到~/.ssh/know_hosts
如果身份驗證改變,拒絕連線會出現以下效果
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:qFJoGa0HY3fBnHaMwCBhq5d017at0BcRdOJ3kULqrDM.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:1
ECDSA host key for 172.25.254.4has changed and you have requested strict checking.
在這裡插入圖片描述

當連線因為認證問題被拒絕時解決方案

vim ~/.ssh/know_hosts ###在這個檔案中刪除報錯的相應的提示的行即可
在這裡插入圖片描述

ssh 常用引數

ssh -l指定登入使用者

在這裡插入圖片描述

ssh -i指定私鑰
ssh -X開啟影像

在這裡插入圖片描述

ssh -o指定連線引數#ssh -l root@172.25.254.x -o

在這裡插入圖片描述

ssh -f後臺執行

在這裡插入圖片描述

ssh -t指定連線跳板

在這裡插入圖片描述

三、sshd key認證

1、認證型別

#對稱加密
加密和解密是同以以一串字元
容易洩漏可暴力破解容易遺忘
#非對稱加密
加密用公鑰,解密用私鑰
不會被盜用
攻擊者無法通過無金鑰方式登陸伺服器

2、生成非對稱加密金鑰

方法一:ssh-keygen
在這裡插入圖片描述
Generating public/private rsa key pair. Enter file in which to save the key (/home/lee/.ssh/id_rsa): ##輸入儲存金鑰檔案Enter passphrase (empty for no passphrase): ##金鑰密碼Enter same passphrase again: ##確認密碼Your identification has been saved in /home/lee/.ssh/id_rsa.##私鑰Your public key has been saved in /home/lee/.ssh/id_rsa.pub.##公鑰The key fingerprint is:SHA256:rrbJoCb/f+7m5KwEOj2+M2NaCFAg6kxyOuuB+c3kmi8 lee@westos_student7.westos.orgThe key’s randomart image is:
±–[RSA 3072]----+
|o… |
|o. |
|+… |
|*o |
|+o . S |
|.= + . . |
|+.+ * . o |
|o.E@==.o |
| =BBOBBO
|
±—[SHA256]-----+
方法二:ssh-keygen -f /root/.ssh/id_rsa -P “”

3、對伺服器加密

#ssh-copy-id -i /root/.ssh/id_rsa.pub username@ipaddress
例:ssh-copy-id -i /home/linux/.ssh/id_rsa.pub linux@172.25.254.5
在這裡插入圖片描述

四、sshd安全優化引數詳解

#首先輸入setenforce 0
systemctl disable --now firewalld
在這裡插入圖片描述

Port 2222設定埠為2222

在這裡插入圖片描述
在這裡插入圖片描述

PermitRootLogin yes/no對超級使用者登陸是否禁止

在這裡插入圖片描述
在這裡插入圖片描述

PasswordAuthentication yes/no是否開啟原始密碼認證方式

在這裡插入圖片描述
在這裡插入圖片描述

AllowUsers lee使用者白名單,只允許登陸lee使用者

在這裡插入圖片描述
在這裡插入圖片描述

DenyUsers lee使用者黑名單,只不允許登陸lee使用者

在這裡插入圖片描述
在這裡插入圖片描述

相關文章