亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 960 | 回復(fù): 0
打印 上一主題 下一主題

SSH 安全小技巧 [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2007-07-17 16:59 |只看該作者 |倒序?yàn)g覽
一, 前言
關(guān)于 ssh 的好處, 簡(jiǎn)而言之, 之前的 rpc command 與 telnet 都全可用 ssh 代替.
比方如下的這些常見(jiàn)功能:
- 遠(yuǎn)程登錄
ssh
user@remote.machine

- 遠(yuǎn)程執(zhí)行
ssh
user@remote.machine
'command ...'
- 遠(yuǎn)程拷貝
scp
[email=user@remote.machine:/remote/path]user@remote.machine:/remote/path[/email]
/local/path
scp /local/path
[email=user@remote.machine:/remote/path]user@remote.machine:/remote/path[/email]

- X forward
ssh -X
user@remote.machine

xcommand ...
- Tunnel / Portforward
ssh -L 1234:remote.machine:4321
user@remote.machine

ssh -R 1234:local.machine:4321
user@remote.machine

ssh -L 1234:other.machine:4321
user@remote.machine


這里要說(shuō)的, 是針對(duì) ssh 服務(wù)為大家介紹一些安全技巧, 希望大家用得更安心些.
二, 實(shí)作
(實(shí)作以 RedHat 9 為范例)

1) 禁止 root 登錄
# vi /etc/ssh/sshd_config
PermitRootLogin no

2) 廢除密碼登錄, 強(qiáng)迫使用 RSA 驗(yàn)證(假設(shè) ssh 賬戶為 user1 )
# vi /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile     .ssh/authorized_keys
PasswordAuthentication no
# service sshd restart
# su - user1
$ mkdir ~/.ssh 2>/dev/null
$ chmod 700 ~/.ssh
$ touch ~/.ssh/authorized_keys
$ chmod 644 ~/.ssh/authorized_keys
--------------------------------------------------
轉(zhuǎn)往 client 端:
$ ssh-keygen -t rsa
(按三下 enter 完成﹔不需設(shè)密碼,除非您會(huì)用 ssh-agent 。)
$ scp ~/.ssh/id_rsa.pub
[email=user1@server.machine:id_rsa.pub]user1@server.machine:id_rsa.pub[/email]

(若是 windows client, 可用 puttygen.exe 產(chǎn)生 public key,
然后復(fù)制到 server 端后修改之, 使其內(nèi)容成為單一一行.)
---------------------------------------------------
回到 server 端:
$ cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
$ rm ~/id_rsa.pub
$ exit

3) 限制 su / sudo 名單:
# vi /etc/pam.d/su
auth  required  /lib/security/$ISA/pam_wheel.so use_uid
# visudo
%wheel  ALL=(ALL)   ALL
# gpasswd -a user1 wheel

4) 限制 ssh 使用者名單
# vi /etc/pam.d/sshd
auth       required     pam_listfile.so item=user sense=allow file=/etc/ssh_users onerr=fail
# echo user1 >> /etc/ssh_users

5) 封鎖 ssh 聯(lián)機(jī)并改用 web 控管清單
# iptables -I INPUT -p tcp --dport 22 -j DROP
# mkdir /var/www/html/ssh_open
# cat > /var/www/html/ssh_open/.htaccess  /var/www/html/ssh_open/ssh_open.php
//Set filename for ip list
$ip_list="ssh_open.txt";
//Get client ip
$user_ip=$_SERVER['REMOTE_ADDR'];
//allow specifying ip if needed
if (@$_GET['myip']) {
$user_ip=$_GET['myip'];
}
//checking IP format
if ($user_ip==long2ip(ip2long($user_ip))) {
//Put client ip to a file
if(@!($file = fopen("$dir_path/$ip_list","w+")))
{
       echo "Permission denied!!
";
       echo "Pls Check your rights to dir $dir_path or file $ip_list";
}
else
{
       fputs($file,"$user_ip");
       fclose($file);
       echo "client ip($user_ip) has put into $dir_path/$ip_list";
}
} else {
echo "Invalid IP format!!
ssh_open.txt was not changed.";
}
?>
END
# touch /var/www/html/ssh_open/ssh_open.txt
# chmod 640 /var/www/html/ssh_open/*
# chgrp apache /var/www/html/ssh_open/*
# chmod g+w /var/www/html/ssh_open/ssh_open.txt
# chmod o+t /var/www/html/ssh_open
# service httpd restart
# mkdir /etc/iptables
# cat > /etc/iptables/sshopen.sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
list_dir=/var/www/html/ssh_open
list_file=$list_dir/ssh_open.txt
chain_name=ssh_rules
mail_to=root
# clear chain if exits, or create chain.
iptables -L -n | /bin/grep -q "^Chain $chain_name" && {
       iptables -F $chain_name
       true
} || {
       iptables -N $chain_name
       iptables -I INPUT -p tcp --dport 22 -j $chain_name
}
# clear chain when needed
[ "$1" = clear ] && {
       iptables -F $chain_name
       exit 0
}
# do nothing while list is empty
[ -s $list_file ] || exit 1
# add rule
iptables -A $chain_name -p tcp --dport 22 -s $(> /etc/services
# cat > /etc/xinetd.d/sshopen  /etc/cron.d/sshopen
---------------------------
轉(zhuǎn)往 client 端
在 browser URL 輸入:
http://server.machine/ssh_open/ssh_open.php?myip=1.2.3.4

(若不指定 ?myip=1.2.3.4 則以 client 當(dāng)時(shí) IP 為準(zhǔn), 若沒(méi)經(jīng) proxy 的話.)
如此, server 端的 ssh_open.txt 文件只有單一記錄, 每次蓋寫.
接著:
$ telnet server.machine 1234
然后你有最多 5 分鐘時(shí)間用 ssh 聯(lián)機(jī) server !
---------------------------
此步驟的基本構(gòu)思如下:
5.1) 將 sshd 的 firewall 聯(lián)機(jī)全部 block 掉.
5.2) 然后在 httpd 那設(shè)一個(gè) directory, 可設(shè) ssl+htpasswd+allow/deny control,
然后在目錄內(nèi)寫一個(gè) php 將 browser ip 記錄于一份 .txt 文字文件里.
視你的轉(zhuǎn)寫能力, 你可自動(dòng)抓取 browser 端的 IP, 也可讓 browser 端傳入?yún)?shù)來(lái)指定.
文字文件只有單一記錄, 每次蓋寫.
5.3) 修改 /etc/services , 增加一個(gè)新項(xiàng)目(如 xxx), 并指定一個(gè)新 port(如 1234)
5.4) 再用 xinetd 監(jiān)聽(tīng)該 port , 并啟動(dòng)令一只 script, 設(shè)定 iptables , 從 step2 的清單里取得 IP, 為之打開(kāi) ssh 聯(lián)機(jī).
5.5) 設(shè) crontab 每數(shù)分中清理 iptables 關(guān)于 ssh 聯(lián)機(jī)的規(guī)則. 這并不影響既有聯(lián)機(jī), 若逾時(shí)再連, 則重復(fù)上述.

6) 要是上一步驟沒(méi)設(shè)定, 你或許會(huì)擔(dān)心過(guò)多的人來(lái) try 你的 ssh 服務(wù)的話:
# cat > /etc/iptables/sshblock.sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin
LOG_FILE=/var/log/secure
KEY_WORD="Illegal user"
KEY_WORD1="Failed password for root"
PERM_LIST=/etc/firewall/bad.list.perm
LIMIT=5
MAIL_TO=root
IPT_SAV="$(iptables-save)"
bad_list=$(egrep "$KEY_WORD" $LOG_FILE | awk '{print $NF}' | xargs)
bad_list1=$(egrep "$KEY_WORD1" $LOG_FILE | awk '{print $11}' | xargs)
bad_list="$bad_list $bad_list1"
for i in $(echo -e "${bad_list// /\n}" | sort -u)
do
       hit=$(echo $bad_list | egrep -o "$i" | wc -l)
       [ "$hit" -ge "$LIMIT" ] && {
               echo "$IPT_SAV" | grep -q "$i .*-j DROP" || {
                       echo -e "\n$i was dropped on $(date)\n" | mail -s "DROP by ${0##*/}: $i" $MAIL_TO
                       iptables -I INPUT -s $i -j DROP
               }
               egrep -q "^$i$" $PERM_LIST || echo $i >> $PERM_LIST
       }
done
END
# chmod +x /etc/firewall/sshblock.sh
# cat >> /etc/hosts.allow
這樣, 那些亂 try SSH 的家伙, 頂多能試 5 次(LIMIT 可調(diào)整), 然后就給 BLOCK 掉了.
此外, 在 PERM_LIST 的 ip, 也可提供給 iptables 的初始 script , 來(lái)個(gè)永久性封閉:
for i in $(

7) 還有, 你想知道有哪些人對(duì)你做 full range port scan 的話:
# iptables -I INPUT -p tcp --dport 79 -j ACCEPT
cat > /etc/xinetd.d/finger > /etc/hosts.allow
這里, 我只是設(shè)為發(fā)信給 root.
事實(shí)上, 你可修改為起動(dòng) firewall 將 %a 這個(gè)傳回值給 ban 掉也行.
不過(guò), 對(duì)方要是有選擇性的做 port scan , 沒(méi)掃到 finger 的話, 那當(dāng)然就沒(méi)用了...
三, 結(jié)語(yǔ)


本文來(lái)自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u/18079/showart_341867.html
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP