-
互聯(lián)網(wǎng)安全法,互聯(lián)網(wǎng)凈網(wǎng)行動(dòng)
-
”凈網(wǎng)2020”落實(shí)好維護(hù)網(wǎng)絡(luò)安全責(zé)任
-
關(guān)于端午節(jié)放假通知-宇眾網(wǎng)絡(luò)
-
宇眾網(wǎng)絡(luò)春節(jié)放假通知
-
關(guān)于公司收款銀行賬戶變更通知函-宇眾網(wǎng)絡(luò)
-
關(guān)于網(wǎng)上有人冒充我公司名義進(jìn)行詐騙的公告。
-
關(guān)于端午節(jié)放假通知,節(jié)日放假,但是我們業(yè)務(wù)不“放假”-宇眾網(wǎng)絡(luò)
-
工信部進(jìn)一步加強(qiáng)未備案網(wǎng)站管理工作的通知-宇眾網(wǎng)絡(luò)
-
關(guān)于東莞市宇眾網(wǎng)絡(luò)科技有限公司香港數(shù)據(jù)中心(香港機(jī)房)路由優(yōu)化通知
-
宇眾網(wǎng)絡(luò)慶祝五·一勞動(dòng)節(jié)快樂
-
東莞東城機(jī)房網(wǎng)絡(luò)升級(jí)通知
-
臨近過年,互聯(lián)網(wǎng)IDC貴圈也有被騙的,請(qǐng)認(rèn)準(zhǔn)宇眾網(wǎng)絡(luò)公司官方聯(lián)系方式
-
我司已獲得ISP/ICP/IDC三證資格,更好的為客戶服務(wù)
-
關(guān)于浙江金華高防機(jī)房網(wǎng)絡(luò)線路切割通知
-
工信部近日下發(fā)關(guān)于進(jìn)一步規(guī)范域名備案工作的通知
行業(yè)資訊
- 首頁(yè)
- 新聞中心
- 行業(yè)資訊
服務(wù)器遠(yuǎn)程訪問及控制
標(biāo)題 遠(yuǎn)程訪問及控制
*學(xué)會(huì)構(gòu)建SSH遠(yuǎn)程登錄服務(wù)
*學(xué)會(huì)使用SSH客戶端工具
*學(xué)會(huì)編寫TCP Wrappers訪問策略
實(shí)驗(yàn)環(huán)境:
開啟2臺(tái)linux虛擬機(jī)
- linux-1 openssh服務(wù)器
僅主機(jī) 192.168.10.1
nat 200.1.1.1
2.linux-2 外網(wǎng)客戶端
nat 200.1.1.10
3.windows 主機(jī) 內(nèi)網(wǎng)客戶機(jī)
僅主機(jī) 192.168.10.10
OpenSSH服務(wù)器
- 1
1.SSH協(xié)議(安全通道協(xié)議)
*為客戶機(jī)提供安全的Shell環(huán)境,用于遠(yuǎn)程管理(生產(chǎn)環(huán)境多用),遠(yuǎn)程登錄、遠(yuǎn)程雙向復(fù)制scp,遠(yuǎn)程文件傳輸sftp;安全性高。
*默認(rèn)端口:TCP 22
2.OpenSSH
*服務(wù)名稱:sshd
*服務(wù)端主程序:/usr/sbin/sshd
*服務(wù)端配置文件:/etc/ssh/sshd_config
為了提高安全性,可做下列配置
3。服務(wù)監(jiān)聽選項(xiàng)
*端口號(hào)、協(xié)議版本、監(jiān)聽I(yíng)P地址
*禁用反向解析
[root@localhost ~]# cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
[root@localhost ~]# vi /etc/ssh/sshd_config
……
17 Port 22 ***可更改端口
18 Protocol 2 ***版本2比版本1安全性高
20 ListenAddress 192.168.10.1 ***偵聽地址
116 UseDNS no ***禁用反向解析,提高服務(wù)器響應(yīng)速度(添加)
[root@localhost ~]# systemctl restart sshd
驗(yàn)證:外網(wǎng)客戶機(jī) 200.1.1.2
[root@localhost ~]# ssh root@192.168.10.1
[root@localhost ~]# ssh root@200.1.1.1
ssh: connect to host 200.1.1.1 port 22: Connection refused
如果要實(shí)現(xiàn)可訪問,openssh服務(wù)器添加偵聽地址
ListenAddress 200.1.1.1
4.用戶登錄控制
*禁止root用戶、空密碼用戶—(普通用戶登錄–>切換到root)
*登錄時(shí)間、重試次數(shù)
*AllowUsers、DenyUsers
[root@localhost ~]# useradd tom
[root@localhost ~]# useradd jack
[root@localhost ~]# echo “123” |passwd --stdin tom
更改用戶 tom 的密碼 。
passwd:所有的身份驗(yàn)證令牌已經(jīng)成功更新。
[root@localhost ~]# echo “123” |passwd --stdin jack
更改用戶 jack 的密碼 。
passwd:所有的身份驗(yàn)證令牌已經(jīng)成功更新。
[root@localhost ~]# vi /etc/ssh/sshd_config
……
40 PermitRootLogin no *** 禁止root用戶
66 PermitEmptyPasswords no ***禁止空密碼用戶
39 LoginGraceTime 2m ***登錄驗(yàn)證時(shí)間2分鐘
42 MaxAuthTries 6 ***最大重試次數(shù)
……
末尾添加:
AllowUsers tom jack@200.1.1.10 ***允許tom登錄;允許jack只能在此地址登錄
*可設(shè)置AllowUsers和DenyUsers,【不要與DenyUsers同時(shí)用】
[root@localhost ~]# systemctl restart sshd
驗(yàn)證:允許tom登錄;允許jack只能在此地址登錄
5.登錄驗(yàn)證對(duì)象
*服務(wù)器中的本地用戶賬號(hào)—例:tom
6.登錄驗(yàn)證方式
*密碼驗(yàn)證:核對(duì)用戶名、密碼是否匹配—安全性弱,易被攻擊
*密鑰對(duì)驗(yàn)證:核對(duì)客戶的私鑰、服務(wù)端公鑰是否匹配
— 客戶機(jī)創(chuàng)建秘鑰對(duì)(公鑰、私鑰)–>公鑰存放到服務(wù)器
— 密碼、秘鑰同時(shí)啟用,優(yōu)先使用密鑰
—公鑰庫(kù)文件可保存多個(gè)公鑰
[root@localhost ~]# vi /etc/ssh/sshd_config
……
【啟用密碼驗(yàn)證、密鑰對(duì)驗(yàn)證、指定公鑰庫(kù)位置】
PasswordAuthentication yes ***密碼驗(yàn)證
PubkeyAuthentication yes ** 秘鑰對(duì)驗(yàn)證
AuthorizedKeysFile .ssh/authorized_keys 指定公鑰庫(kù)數(shù)據(jù)文件位置
使用SSH客戶端程序
- 1
1.ssh命令 —— 遠(yuǎn)程安全登錄 【端口選項(xiàng):-p 22】
*格式:ssh user@host
2.scp命令 —— 遠(yuǎn)程安全復(fù)制
*格式1:scp user@host:file1 file2
*格式2:scp file1 user@host:file2
3.sftp命令 —— 安全FTP上下載
格式:sftp user@host
4.Xshell
*Windows下一款功能非常強(qiáng)大的安全終端模擬軟件
linux-1:
[root@localhost ~]# cp /etc/ssh/sshd_config.bak /etc/ssh/sshd_config
cp:是否覆蓋"/etc/ssh/sshd_config"? y
[root@localhost ~]# systemctl restart sshd
su - tom
$ touch tom.txt
linux-2:
[root@localhost ~]# useradd zhangsan
[root@localhost ~]# useradd lisi
[root@localhost ~]# echo “123” |passwd --stdin zhangsan
[root@localhost ~]# echo “123” |passwd --stdin lisi
[root@localhost ~]# su - lisi
[lisi@localhost ~]$ touch lisi.txt
[lisi@localhost ~]$ ssh tom@192.168.10.1
The authenticity of host ‘192.168.10.1 (192.168.10.1)’ can’t be established.
ECDSA key fingerprint is SHA256:T+Kaqay4bTpIR3BBJ1x8EXaE3ukPjDMGEqMLPAaqaQg.
ECDSA key fingerprint is MD5:3e:1d:ef:74:ae:15:bb:3f:f1:cc:53:07:64:e2:ef:f9.
—根據(jù)服務(wù)端發(fā)送過來的RSA密鑰輸入‘yes’驗(yàn)證
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘192.168.10.1’ (ECDSA) to the list of known hosts.
—輸入tom密碼
tom@192.168.10.1’s password:
Last login: Thu Oct 25 14:34:00 2018
[tom@localhost ~]$ pwd
/home/tom
[tom@localhost ~]$ ls
tom.txt
[tom@localhost ~]$ exit
登出
Connection to 192.168.10.1 closed.
[lisi@localhost ~]$ scp tom@192.168.10.1:tom.txt tom.txt
tom@192.168.10.1’s password:
tom.txt 100% 0 0.0KB/s 00:00
[lisi@localhost ~]$ scp lisi.txt tom@192.168.10.1:lisi.txt
tom@192.168.10.1’s password:
lisi.txt 100% 0 0.0KB/s 00:00
[lisi@localhost ~]$ ssh tom@192.168.10.1 ls
tom@192.168.10.1’s password:
lisi.txt
tom.txt
[lisi@localhost ~]$ touch test1.txt
[lisi@localhost ~]$ sftp tom@192.168.10.1
tom@192.168.10.1’s password:
Connected to 192.168.10.1.
sftp> lls
lisi.txt test1.txt tom.txt
sftp> ls
lisi.txt tom.txt
sftp> put test1.txt
Uploading test1.txt to /home/tom/test1.txt
test1.txt 100% 0 0.0KB/s 00:00
sftp> ls
lisi.txt test1.txt tom.txt
sftp> bye
構(gòu)建密鑰對(duì)驗(yàn)證的SSH體系(ssh信任)
- 1
1.整體實(shí)現(xiàn)過程
原理;由客戶端的用戶zhangsan、lisi在本地創(chuàng)建密鑰對(duì)
導(dǎo)入到服務(wù)端用戶tom的公鑰數(shù)據(jù)庫(kù)(然后就可以在客戶端zhangsan、lisi登錄的情況下ssh到服務(wù)器tom用戶了)
第一步:創(chuàng)建密鑰對(duì)(zhangsan的密鑰對(duì),在Linux客戶機(jī)的…/.ssh里面)
私鑰文件:id_rsa
公鑰文件:id_rsa.pub
第二步:上傳公鑰文件 id_rsa.pub
第三步:導(dǎo)入公鑰信息()
公鑰庫(kù)文件:~/.ssh/authorized_keys
第四步:使用密鑰對(duì)驗(yàn)證方式【以服務(wù)端的用戶tom的身份進(jìn)行登錄】
linux-1
[tom@localhost ~]$ su -
[root@localhost ~]# vim /etc/ssh/sshd_config
43 PubkeyAuthentication yes
47 AuthorizedKeysFile .ssh/authorized_keys
[root@localhost ~]# systemctl restart sshd
linux-2 客戶機(jī)
- 在客戶機(jī)中創(chuàng)建密鑰對(duì)
*ssh-keygen命令
*可用的加密算法:escda或DSA
[lisi@localhost ~]$ su -
[root@localhost ~]# su - zhangsan
[zhangsan@localhost ~]$ ll .ssh
ls: 無法訪問.ssh: 沒有那個(gè)文件或目錄
[zhangsan@localhost ~]$ ssh-keygen -t ecdsa
Generating public/private ecdsa key pair.
Enter file in which to save the key (/home/zhangsan/.ssh/id_ecdsa): 默認(rèn)位置
Created directory ‘/home/zhangsan/.ssh’.
Enter passphrase (empty for no passphrase): 默認(rèn)回車
Enter same passphrase again: 默認(rèn)回車
Your identification has been saved in /home/zhangsan/.ssh/id_ecdsa.
Your public key has been saved in /home/zhangsan/.ssh/id_ecdsa.pub.
The key fingerprint is:
SHA256:byF6T/5YXG/9D9I5xqcfiI8isugc6z5BNyHQkTohaoI zhangsan@localhost.localdomain
The key’s randomart image is:
±–[ECDSA 256]—+
| .o.o |
|… + . |
|+ o . . |
|E+ . o |
|o o . . S . . |
| . . o o.+.o.|
| … . . +.+.B.=|
| …+. o * ooo *o|
| +B…o . =o…=|
±—[SHA256]-----+
[zhangsan@localhost ~]$ ls -lh .ssh/id_ecdsa*
-rw------- 1 zhangsan zhangsan 227 10月 25 14:45 .ssh/id_ecdsa
-rw-r–r-- 1 zhangsan zhangsan 192 10月 25 14:45 .ssh/id_ecdsa.pub
方法1:
?2. 將公鑰文件上傳至服務(wù)器
*任何方式均可(共享、FTP、Email、SCP、……)
[zhangsan@localhost ~]$ scp .ssh/id_ecdsa.pub tom@192.168.10.1:zhangsan.key
- 在服務(wù)器中導(dǎo)入公鑰文本
*將公鑰文本添加至目標(biāo)用戶的公鑰庫(kù)
*默認(rèn)公鑰庫(kù)位置:~/.ssh/authorized_keys
SSH對(duì)公鑰、私鑰的權(quán)限和所有權(quán)的要求是非常嚴(yán)格的
— .ssh 目錄權(quán)限 700
— .ssh/authorized_keys 權(quán)限644
— .ssh/id_rsa 私鑰文件權(quán)限必須是600
[zhangsan@localhost ~]$ ssh tom@192.168.10.1
[tom@localhost ~]$ ll .ssh
【tom的家目錄本來沒有authorized_keys】
[tom@localhost ~]$ mkdir .ssh
[tom@localhost ~]$ touch .ssh/authorized_keys
[tom@localhost ~]$ chmod 700 .ssh
[tom@localhost ~]$ chmod 644 .ssh/authorized_keys
[tom@localhost ~]$ cat zhangsan.key >> .ssh/authorized_keys
---選擇‘>>’,公鑰庫(kù)可存放多個(gè)用戶的公鑰
- 1
[tom@localhost ~]$ cat .ssh/authorized_keys
—庫(kù)中==后為聲明
[zhangsan@localhost ~]$ ls -lh .ssh/
總用量 12K
-rw------- 1 zhangsan zhangsan 227 10月 25 14:45 id_ecdsa
-rw-r–r-- 1 zhangsan zhangsan 192 10月 25 14:45 id_ecdsa.pub
-rw-r–r-- 1 zhangsan zhangsan 174 10月 25 14:49 known_hosts
[zhangsan@localhost ~]$ ls -ldh .ssh/
drwx------ 2 zhangsan zhangsan 61 10月 25 14:49 .ssh/
[zhangsan@localhost ~]$ ssh tom@192.168.10.1
方法2:*驗(yàn)證密碼后,會(huì)將公鑰自動(dòng)添加到目標(biāo)主機(jī)user宿主目錄下的.ssh/authorized_keys文件結(jié)尾
*ssh-copy-id -i 公鑰文件 user@host
[zhangsan@localhost ~]$ exit
登出
[root@localhost ~]# su - lisi
[lisi@localhost ~]$ ssh-keygen -t ecdsa
[lisi@localhost ~]$ ssh-copy-id -i .ssh/id_ecdsa.pub tom@192.168.10.1
— -i 指定公鑰文件
[lisi@localhost ~]$ ssh tom@192.168.10.1
[tom@localhost ~]$ cat .ssh/authorized_keys
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAZydP4XKVX6GGR9DLcKIW/nYZY+sLenMYnIaOrPrRhZ14tfGg1c+7JOWkd2yEL+VaXrhkRpjPCdOJfXoHT4vuU= zhangsan@localhost.localdomain
ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBE/gMz/L6FSUJC7fSy/0/cW/8+DB4QSSvxLHhmdpIspy4EvQ5hzvCI1Q4N0He6kIf82U0rv3SJEofdsRcD7/8Yg= lisi@localhost.localdomain
TCP Wrappers概述
- 1
1.TCP Wrappers機(jī)制
【客戶機(jī)的網(wǎng)絡(luò)訪問請(qǐng)求】
1)對(duì)訪問請(qǐng)求進(jìn)行過濾控制
代為監(jiān)聽端口21
代為監(jiān)聽端口23
代為監(jiān)聽端口110
代為監(jiān)聽端口143
2)調(diào)用相應(yīng)的網(wǎng)絡(luò)程序
vsftpd
telnet
ipop3
imap
2.保護(hù)機(jī)制的實(shí)現(xiàn)方式
方式1:通過tcpd主程序?qū)ζ渌?wù)程序進(jìn)行包裝
方式2:由其他服務(wù)程序調(diào)用libwrap.so.*鏈接庫(kù)
3.訪問控制策略的配置文件
/etc/hosts.allow
/etc/hosts.deny
TCP Wrappers(tcp封套)策略應(yīng)用
- 1
在 wrappers 下進(jìn)行訪問控制的通常有 telnet、ssh、sendmail、ftp 包、pop3 和 stunnel。
主配置文件:
/etc/hosts.allow
/etc/hosts.deny
*執(zhí)行程序: tcpd
共享鏈接庫(kù)文件: libwrap.so.
–這種方式更廣泛
查看程序的共享庫(kù) ldd
ldd /usr/sbin/sshd |grep “libwrap”
1.設(shè)置訪問控制策略
*策略格式:服務(wù)列表:客戶機(jī)地址列表
2.服務(wù)列表 ——
*多個(gè)服務(wù)以逗號(hào)分隔,ALL 表示所有服務(wù)
3.客戶機(jī)地址列表
*多個(gè)地址以逗號(hào)分隔,ALL表示所有地址
*允許使用通配符 ? 和 *
*網(wǎng)段地址,如 192.168.4. 或者 192.168.4.0/255.255.255.0
*區(qū)域地址,如 .benet.com
—匹配域中所有主機(jī)
4.策略的應(yīng)用順序
*先檢查hosts.allow,找到匹配則允許訪問
*否則再檢查hosts.deny,找到則拒絕訪問
*若兩個(gè)文件中均無匹配策略,則默認(rèn)允許訪問
5.策略應(yīng)用示例
*僅允許從以下地址訪問sshd服務(wù)
&主機(jī)192.168.10.3
&網(wǎng)段192.168.2.0/24
*禁止其他所有地址訪問受保護(hù)的服務(wù)
[root@localhost ~]# ll /etc/hosts.*
-rw-r–r--. 1 root root 370 6月 7 2013 /etc/hosts.allow
-rw-r–r--. 1 root root 460 6月 7 2013 /etc/hosts.deny
[root@localhost ~]# vim /etc/hosts.allow
sshd:192.168.10.*,200.1.1.3
[root@localhost ~]# vi /etc/hosts.deny
sshd:ALL
驗(yàn)證:在客戶機(jī)ssh登錄驗(yàn)證
[root@localhost ~]# ssh root@200.1.1.1
更改hosts.allow為sshd:192.168.10.*,200.1.1.2繼續(xù)驗(yàn)證
總結(jié):配置策略要2個(gè)文件都做配置