日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

ssh安装与配置

發布時間:2024/4/14 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ssh安装与配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

SSH?為 Secure Shell 的縮寫,由 IETF 的網絡工作小組(Network Working Group)所制定;SSH 為建立在應用層傳輸層基礎上的安全協議。

傳統的網絡服務程序,如FTP、POP和Telnet其本質上都是不安全的;因為它們在網絡上用明文傳送數據、用戶帳號和用戶口令,很容易受到中間人(man-in-the-middle)攻擊方式的攻擊。就是存在另一個人或者一臺機器冒充真正的服務器接收用戶傳給服務器的數據,然后再冒充用戶把數據傳給真正的服務器。

而 SSH 是目前較可靠,專為遠程登錄會話和其他網絡服務提供安全性的協議。利用 SSH 協議可以有效防止遠程管理過程中的信息泄露問題。透過?SSH?可以對所有傳輸的數據進行加密,也能夠防止 DNS 欺騙和 IP 欺騙。

?

系統及版本:CentOS?release 5.3 (Final)

安裝SSH

yum install ssh

啟動SSH

service sshd start

設置開機運行

chkconfig sshd on

?

?

SSH相關配置文件的修改

?

  首先修改SSH的配置文件。如下:

?

[root@sample ~]#?vi /etc/ssh/sshd_config ?← 用vi打開SSH的配置文件

?

#Protocol 2,1 ← 找到此行將行頭“#”刪除,再將行末的“,1”刪除,只允許SSH2方式的連接
 ↓
Protocol 2 ← 修改后變為此狀態,僅使用SSH2

#ServerKeyBits 768 ← 找到這一行,將行首的“#”去掉,并將768改為1024

 ↓
ServerKeyBits 1024 ← 修改后變為此狀態,將ServerKey強度改為1024比特

#PermitRootLogin yes? ← 找到這一行,將行首的“#”去掉,并將yes改為no
 ↓
PermitRootLogin no? ← 修改后變為此狀態,不允許用root進行登錄

#PasswordAuthentication yes ← 找到這一行,將yes改為no
 ↓
PasswordAuthentication no ← 修改后變為此狀態,不允許密碼方式的登錄

#PermitEmptyPasswords no ?← 找到此行將行頭的“#”刪除,不允許空密碼登錄
 ↓
PermitEmptyPasswords no ?← 修改后變為此狀態,禁止空密碼進行登錄

?

  然后保存并退出。(vi保存退出的命令為ZZ)

  因為我們只想讓SSH服務為管理系統提供方便,所以在不通過外網遠程管理系統的情況下,只允許內網客戶端通過SSH登錄到服務器,以最大限度減少不安全因素。設置方法如下:

?

[root@sample ~]#?vi /etc/hosts.deny ?← 修改屏蔽規則,在文尾添加相應行

?

#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the ‘/usr/sbin/tcpd’ server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!

sshd: ALL ?← 添加這一行,屏蔽來自所有的SSH連接請求

[root@sample ~]#?vi /etc/hosts.allow ?← 修改允許規則,在文尾添加相應行

#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the ‘/usr/sbin/tcpd’ server.
#

sshd: 192.168.0. ?← 添加這一行,只允許來自內網的SSH連接請求

?

?

?

重啟動SSH啟動

?

  在修改完SSH的配置文件后,需要重新啟動SSH服務才能使新的設置生效。

?

[root@sample ~]#?/etc/rc.d/init.d/sshd restart ?← 重新啟動SSH服務器

?

Stopping sshd:             [?OK?]
Starting sshd:             [?OK?] ?← SSH服務器重新啟動成功

?

  這時,在遠程終端(自用PC等等)上,用SSH客戶端軟件以正常的密碼的方式是無法登錄服務器的。為了在客戶能夠登錄到服務器,我們接下來建立SSH用的公鑰與私鑰,以用于客戶端以“鑰匙”的方式登錄SSH服務器。

?

SSH2的公鑰與私鑰的建立

?

  登錄為一個一般用戶,基于這個用戶建立公鑰與私鑰。(這里以centospub用戶為例)

?

[root@sample ~]#?su – centospub ← 登錄為一般用戶centospub

?

[centospub@sample ~]$?ssh-keygen -t rsa? ← 建立公鑰與私鑰
Generating public/private rsa key pair.
Enter file in which to save the key (/home/kaz/.ssh/id_rsa):? ← 鑰匙的文件名,這里保持默認直接回車

Created directory ‘/home/kaz/.ssh’
Enter passphrase (empty for no passphrase):? ← 輸入口令

Enter same passphrase again:? ?← 再次輸入口令
Your identification has been saved in /home/kaz/.ssh/id_rsa.
Your public key has been saved in /home/kaz/.ssh/id_rsa.pub.
The key fingerprint is:
tf:rs:e3:7s:28:59:5s:93:fe:33:84:01:cj:65:3b:8e centospub@sample.centospub.com

?

  然后確認一下公鑰與密鑰的建立,以及對應于客戶端的一些處理。

?

[centospub@sample ~]$?cd ~/.ssh ?← 進入用戶SSH配置文件的目錄

?

[centospub@sample .ssh]$?ls -l ?← 列出文件
total 16
-rw——- 1 centospub centospub 951 Sep 4 19:22?id_rsa ?← 確認私鑰已被建立

-rw-r–r– 1 centospub centospub 241 Sep 4 19:22?id_rsa.pub ?← 確認公鑰已被建立

[centospub@sample .ssh]$?cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys ?← 公鑰內容輸出到相應文件中

[centospub@sample .ssh]$?rm -f ~/.ssh/id_rsa.pub ?← 刪除原來的公鑰文件

[centospub@sample .ssh]$?chmod 400 ~/.ssh/authorized_keys ?← 將新建立的公鑰文件屬性設置為400

?

  然后,將私鑰通過安全的方式轉移到欲通過SSH連接到服務器的PC上。這里,以通過3.5寸磁盤為介質為例:

?

centospub@sample .ssh]$?exit? ?← 退出一般用戶的登錄(返回root的登錄)

?

[root@sample ~]#?mount /mnt/floppy/ ?← 加載軟盤驅動器

[root@sample ~]#?mv /home/centospub/.ssh/id_rsa /mnt/floppy/? ← 將剛剛建立的私鑰移動到軟盤

[root@sample ~]#?umount /mnt/floppy/? ← 卸載軟盤驅動器

?

轉載于:https://www.cnblogs.com/zajsky/p/3443000.html

總結

以上是生活随笔為你收集整理的ssh安装与配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。