已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
SSH的一些安全小技巧前言关于 ssh 的好处, 相信不用我多说了吧? 簡而言之, 之前的 rpc command 于 telnet 都全可用 ssh 代替. 比方如下的這些常見功能:- 远程登录 ssh userremote.machine- 远程执行 ssh userremote.machine command .- 远程复制 scp userremote.machine:/remote/path /local/path scp /local/path userremote.machine:/remote/path- X forward ssh -X userremote.machine xcommand .- Tunnel / Portforward ssh -L 1234:remote.machine:4321 userremote.machine ssh -R 1234:local.machine:4321 userremote.machine ssh -L 1234:other.machine:4321 userremote.machine至於详细的用法, 我這就不說了. 请读者自行研究吧.我这里要说的, 是针对 ssh 服务为大家介绍一些安全技巧, 希望大家用得更安心些实例(以 RedHat 9 为例)轉往 client 端:$ ssh-keygen -t rsa+ 按三下 enter 完成不需設密碼,除非您會用 ssh-agent .$ scp /.ssh/id_rsa.pub user1server.machine:id_rsa.pub+ 若是 windows client, 可用 puttygen.exe 產生 public key, 然後複制到 server 端後修改之, 使其內容成為單一一行.+ 如果 server 端已經禁止密碼登入, 那請用其它放法復製 publick key.登入 server 端:1) 禁止 root 登錄# vi /etc/ssh/sshd_configPermitRootLogin no2) 廢除密碼登錄, 強迫使用 RSA 驗證(假設 ssh 帳戶為 user1 )# vi /etc/ssh/sshd_configRSAAuthentication yesPubkeyAuthentication yesAuthorizedKeysFile .ssh/authorized_keysPasswordAuthentication no# service sshd restart# su - user1$ mkdir /.ssh 2/dev/null$ chmod 700 /.ssh$ touch /.ssh/authorized_keys$ chmod 644 /.ssh/authorized_keys$ cat /id_rsa.pub /.ssh/authorized_keys$ rm /id_rsa.pub$ exit3) 限制 su / sudo 名單:# vi /etc/pam.d/suauth required /lib/security/$ISA/pam_wheel.so use_uid# visudo%wheel ALL=(ALL) ALL# gpasswd -a user1 wheel4) 限制 ssh 使用者名單# vi /etc/pam.d/sshdauth required pam_listfile.so item=user sense=allow file=/etc/ssh_users onerr=fail# echo user1 /etc/ssh_users5) 封鎖 ssh 連線並改用 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 END?/Set dir path for ip list$dir_path=.;/Set filename for ip list$ip_list=ssh_open.txt;/Get client ip$user_ip=$_SERVERREMOTE_ADDR;/allow specifying ip if neededif ($_GETmyip) $user_ip=$_GETmyip;/checking IP formatif ($user_ip#long2ip(ip2long($user_ip) /Put client ip to a fileif(!($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 $list_file exit 0# do nothing while list is empty -s $list_file | exit 1# deny connection if host dosnt math to listhost_ip=$(grep myssh from= $auth_log | tail -1 | awk -F= print $NF)list_ip=$(cat $list_file)if -n $host_ip -a $host_ip != $list_ip ; then echo -e $trusted_ip/ /n | grep -q $host_ip | /sbin/iptables-save | grep -q INPUT -s $host_IP -j DROP$ | /sbin/iptables -I INPUT -s $host_ip -j DROP echo $host_ip $bad_list echo $host_ip is blocked by $0 on $(date) | mail -s block ip $mail_to exit 2fi# add ruleiptables -A $chain_name -p tcp -dport 22 -s $( $list_file) -j ACCEPT & echo ssh opened to $( /etc/services# cat /etc/xinetd.d/sshopen /etc/cron.d/sshopen /etc/iptables/sshblock.sh $PERM_LIST doneEND# chmod +x /etc/firewall/sshblock.sh# cat /etc/hosts.allow ENDsshd: ALL: spawn ( /etc/firewall/sshblock.sh )& : ALLOWEND這樣, 那些亂 try SSH 的家夥, 頂多能試 5 次(LIMIT 可調整), 然後就給 BLOCK 掉了. 此外, 在 PERM_LIST 的 ip, 也可提供給 iptables 的初始 script , 來個永久性封閉: for i in $( /etc/xinetd.d/finger /etc/hosts.allow ENDin.fingerd: ALL : spawn ( echo -e nWAR
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年婴幼儿发展引导员理论重点试题及答案
- 安全生产专项整治三年行动工作总结评估报告
- 《翻译的文化学派》课件
- 气候和生物对土壤性质的影响
- 胶质瘤术前术后护理
- 《快速诱导插管》课件
- 如何设计奴佛卡因胺项目可行性研究报告评审方案2026年发改委立项详细
- 2026年四川建筑安全员C证考试题库(含答案)
- 2026年PCB感光油墨项目调研分析报告
- 2026年小学全部英语模拟试题及答案详解
- 地磅培训知识课件
- 急性盆腔炎护理查房课件
- (正式版)DB42∕T 2305-2024 《高品质住宅技术标准》
- DB14∕T 3151-2024 公路钢波纹管涵洞施工技术规程
- 《关于严格规范涉企行政检查》知识培训
- 人工智能导论知到智慧树章节测试课后答案2024年秋天津大学
- 第六章 人体生命活动的调节【单元测试·提升卷】(原卷版)
- NB-T 20580.9-2021 核电厂建设工程概算定额 第9部分:常规岛电气设备安装工程
- Micro Shield程序初级应用指南
- 金匮要略讲义全套教学课件
- 西方法律思想史正式的课件
评论
0/150
提交评论