通行证: 用户 密码 域名空间  下载中心 社区论坛 信息公告 my小屋
联系我们
设为首页
加入收藏

 

qq,asp,php,jsp,xml,sql,.net,编程 程序 网页图象 建站经验 私服
首页 | 新闻资讯 | 编程开发 | 网页设计 | 图形图象 | 网络媒体 | 网站模板 | 数 据 库 | 投稿
论坛 | 操作系统 | 系统优化 | 网络安全 | 黑客技术 | 硬件学堂 | 硬件报价 | 服 务 器 | 地图
专题 | 应用软件 | 聊天通讯 | q q 专栏 | 建站经验 | 在线工具 | 站长club | 注 册 表 | 旧版
社会 | 游戏娱乐 | 设计欣赏 | 疑难解答 | 社区论坛 | 网络赚钱 | 网站地图 | 广告服务 | 服务
当前位置:首页>>服 务 器>>linux服务器>>正文 新版上线![旧版]
注:打开慢时请稍等
linux ssh 的一些安全小技巧

http://www.iyit.net  日期:2006-5-6 12:24:44  来源:不详  点击:
参加讨论】一, 前言 

关于 ssh 的好处, 相信不用我多说了吧? 
简而言之, 之前的 rpc command 与 telnet 都全可用 ssh 代替. 
比方如下的这些常见功能: 
- 远程登录 
ssh user@remote.machine 
- 远程执行 
ssh user@remote.machine ’command ...’ 
- 远程粗?
scp user@remote.machine:/remote/path /local/path 
scp /local/path user@remote.machine:/remote/path 
- 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 

至于详细的用法, 我这就不说了. 请读者自行研究吧. 
我这里要说的, 是针对 ssh 服务为大家介绍一些安全技巧, 希望大家用得更安心些. 


二, 实作 

(实作以 redhat 9 为范例) 

1) 禁止 root 登录 

# vi /etc/ssh/sshd_config 
permitrootlogin no 

2) 废除密码登录, 强迫使用 rsa 验证(假设 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 

-------------------------------------------------- 
转往 client 端: 
$ ssh-keygen -t rsa 
(按三下 enter 完成﹔不需设密码,除非您会用 ssh-agent 。) 
$ scp ~/.ssh/id_rsa.pub user1@server.machine:id_rsa.pub 
(若是 windows client, 可用 puttygen.exe 产生 public key, 
然后复制到 server 端后修改之, 使其内容成为单一一行.) 
--------------------------------------------------- 

回到 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 联机并改用 web 控管清单 

# iptables -i input -p tcp --dport 22 -j drop 
# mkdir /var/www/html/ssh_open 
# cat > /var/www/html/ssh_open/.htaccess <<end 
authname "ssh_open" 
authuserfile /var/www/html/ssh_open/.htpasswd 
authtype basic 
require valid-user 
end 
# htpasswd -c /var/www/html/ssh_open/.htpasswd user1 
(最好还将 ssl 设起来, 或只限 https 联机更佳, 我这里略过 ssl 设定, 请读者自补.) 
(如需控制联机来源, 那请再补 allow/deny 项目, 也请读者自补.) 
# cat > /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=$_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!!<br>"; 
       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!!<br>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 <<end 
#!/bin/bash 

path=/sbin:/bin:/usr/sbin:/usr/bin 

本新闻共2页,当前在第1页  1  2  


编辑:黑鹰 [发送给好友] [打印本页] [关闭窗口] [返回顶部]
上一篇:引导linux的三种简便方法
下一篇:linux下无线上网设置方法
转载请注明来源:www.iyit.net
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。

 相关文章
linux服务器日志管理详解(3) linux服务器日志管理详解(2) linux服务器日志管理详解(1)
在linux下设置www server(4) 在linux下设置www server(3) 在linux下设置www server(2)
在linux下设置www server(1) 设定linux web 服务器(6) 设定linux web 服务器(5)
设定linux web 服务器(4) 设定linux web 服务器(3) 设定linux web 服务器(2)
设定linux web 服务器(1) 解读linux文件权限的设置方法 一个安全web服务器的安装(三)
一个安全web服务器的安装(二) 一个安全web服务器的安装(一) linux防火墙配置基础篇
浅谈linux优化及安全配置的个人体会 linux的防火墙配置! linux下mysql完全安装使用指南
linux环境下发现并阻止系统攻击 (4) linux环境下发现并阻止系统攻击 (3) linux环境下发现并阻止系统攻击 (2)
最新更新 热点排行 推荐新闻
linux服务器日志管理详解(3)
linux服务器日志管理详解(2)
linux服务器日志管理详解(1)
在linux下设置www server(4)
在linux下设置www server(3)
linux服务器日志管理详解(3)
linux服务器日志管理详解(2)
linux服务器日志管理详解(1)
在linux下设置www server(4)
在linux下设置www server(3)
在linux下设置www server(2)
在linux下设置www server(1)
设定linux web 服务器(6)
设定linux web 服务器(5)
设定linux web 服务器(4)
windows2000下安装apache php4 mysql 
书写linux下自己的shellcode
iis的使用                          
windows 2000下安装php4及mysql大揭密
redhat局域网安装的解决办法
qq珊瑚虫外挂4.0版本发布!
新开放qq免费挂级网站
免费在qq上看在线电影电视听音乐
免费把qq炫铃设为本机qq的系统提示音
摄影后期系列一:1分钟为数码相片去红眼
流金岁月!cpu历史上最难忘的十个第一
教您显示器亮度对比度的调节
腾讯qq调整升级条件不再诱发网民“通宵
qq挂机的n种快速方法
qq挂机说明
巧用photoshop图案工具
用photoshop制成浪漫的“珍珠项链”
第二十章 开发delphi对象式数据管理功
sql简明教程(1)
vbscript和javascript互相调用 
jsp教程(四)-jsp actions的使用
操作系统被入侵后的修复过程
五一别忘电脑防毒 养成良好上网习惯
google对ie浏览器将捆绑搜索功能表担忧
新版上线,今日正式开通!!!
 友情链接
设置首 页 - 版权声明 - 广告服务 - 关于我们 - 联系我们 - 友情连接
copyrights © 2004-2006 iyit.net all rights reserved.
网站合作、广告联系qq:147007642、466949678
易特网络技术 点击这里给我发消息