• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    linux SSH 的一些安全小技巧

    發布: 2007-7-04 12:06 | 作者: admin | 來源:  網友評論 | 查看: 33次 | 進入軟件測試論壇討論

    領測軟件測試網 一, 前言 

    關于 ssh 的好處, 相信不用我多說了吧? 
    簡而言之, 之前的 rpc command 與 te.net 都全可用 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  

    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/


    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>