ssh服務

ssh服務:
SSH爲Secure Shell的縮寫, SSH 爲建立在應用層和傳輸層基礎上的安全協議。SSH是目前可靠的,專爲遠程登錄會話和其他網絡服務提供安全性的協議。常用於遠程登錄,以及用戶之間進行資料拷貝。利用SSH協議可以有效防止遠程管理過程中的信息泄露問題
修改ssh服務端口號
[root@mail ~]# vim /etc/ssh/sshd_config
port 2222
[root@mail ~]# systemctl stop firewalld
[root@mail ~]# setenforce 0
[root@mail ~]# systemctl restart sshd.service
這裏寫圖片描述
拒絕root遠程登錄
[root@mail ~]# vim /etc/ssh/sshd_config
PermitRootLogin no
[root@mail ~]# systemctl restart sshd.service
這裏寫圖片描述
允許特定用戶登錄
[root@mail ~]# vim /etc/ssh/sshd_config
AllowUsers zhangsan lisi
[root@mail ~]# systemctl restart sshd.service
這裏寫圖片描述
這裏寫圖片描述
Ssh互信,免登錄配置
A端:
[root@mail ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory ‘/root/.ssh’.
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:qRxBTMIXWDaC6PNJZ2iVbO70sfeN+m2qeZ+7mODhY4o [email protected]
The key’s randomart image is:
+—[RSA 2048]—-+
| . o+=O. |
|. . oXo. |
|. =.. |
| o + = o . |
| = * o S |
| o o = . |
| o .o. o |
| . oo+++o. |
| E .o**=+*o |
+—-[SHA256]—–+
[root@mail .ssh]# scp id_rsa.pub [email protected]:/root/.ssh
[email protected]’s password:
id_rsa.pub 100% 398 64.4KB/s 00:00
[root@mail .ssh]# ssh 172.16.50.37
Last login: Wed Aug 8 23:09:16 2018 from 172.16.50.60
B端
[root@mail ~]# mkdir .ssh
[root@mail .ssh]# mv id_rsa.pub authorized_keys
root@mail .ssh]# 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:u2PG+XG/FF+5i3fBA4exl/GLzOAteDl7Tk/ckV6OR3s [email protected]
The key’s randomart image is:
+—[RSA 2048]—-+
| |
| . . |
| + +|
| . + ++|
| S o * B+=|
| o * =o@B|
| …o =.o*E|
| *. +.++o+|
| o.o. oo++.|
+—-[SHA256]—–+
[root@mail .ssh]# scp id_rsa.pub [email protected]:/root/.ssh/
[email protected]’s password:
id_rsa.pub 100% 401 236.1KB/s 00:00
A端
[root@mail .ssh]# mv id_rsa.pub authorized_keys
B端
[root@mail .ssh]# ssh 172.16.50.60
Last login: Thu Aug 9 11:35:48 2018 from 172.16.50.222
五:使用證書進行登陸
使用以下命令創建證書:
[root@web ~]# ssh-keygen -t rsa -b 4096
[root@web .ssh]# mv id_rsa.pub authorized_keys
然後將私鑰下載到本地系統(桌面)
在windows系統上使用xshell創建新會話,使用公鑰進行免密登陸
修改配置文件保存退出,重啓服務

發佈了27 篇原創文章 · 獲贊 16 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章