成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

SSH的一些安全小技巧

運維 系統運維
關于 ssh 的好處, 相信不用我多說了吧? 簡而言之, 之前的 rpc command 與 telnet 都全可用 ssh 代替。

 一前言

  關于 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

 

#p#

 

    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 < 

  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 < 

   

  //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!!";

  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 < 

  #!/bin/bash

  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

  }

責任編輯:春曉 來源: 比特網
相關推薦

2022-02-17 13:58:38

Linux技巧文件

2024-03-11 15:08:26

Linux操作系統進程

2009-11-17 17:15:21

路由器安全設置

2015-08-17 15:53:58

Linux桌面

2011-07-19 18:11:09

iPhone 開發

2022-08-28 23:51:04

編輯器vim代碼

2020-09-25 08:28:12

Javascript

2011-06-01 16:50:21

JAVA

2013-03-29 13:17:53

XCode調試技巧iOS開發

2012-05-21 10:13:05

XCode調試技巧

2011-07-12 09:47:53

WebService

2011-05-23 18:06:24

站內優化SEO

2021-10-12 23:10:58

UnsafeJavaJDK

2021-02-16 09:02:59

Python代碼技巧

2019-11-22 10:10:46

IT工具技術

2022-12-02 14:58:27

JavaScript技巧編程

2020-04-08 10:21:58

bash腳本語言

2020-04-14 09:22:47

bash腳本技巧

2009-11-26 10:32:57

PHP代碼優化

2021-11-01 12:10:56

Python技巧代碼
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 天天拍天天射 | 亚洲高清视频在线 | 久久亚洲精品国产精品紫薇 | 亚洲一区二区中文字幕 | 国产污视频在线 | 久久久做 | 色视频网站在线观看 | 美女视频久久 | 久久逼逼 | 久久狠狠 | 亚洲成人精品一区 | 婷婷福利视频导航 | 亚洲国产一区二区在线 | 伊人网国产 | h视频免费在线观看 | 波多野结衣先锋影音 | 久久综合一区 | 国产日韩欧美在线一区 | 色综合久| jizz在线免费观看 | 国产精品国产三级国产aⅴ入口 | 成人三级视频在线观看 | 超碰在线影院 | 久久久久久国产精品 | 国产一区二区久久 | 久草在线青青草 | 黄 色 毛片免费 | 欧美高清视频一区 | 91在线看片 | 久久久久久国产 | 精品一区二区电影 | 九九热在线免费观看 | 国产精品久久精品 | 日韩av在线免费 | 成人欧美一区二区三区在线播放 | 成人网在线观看 | 久久免费精品视频 | 亚洲精品一二三 | 天堂资源 | 97avcc| 草草草久久久 |