Chinaunix首页 | 论坛 | 博客
  • 博客访问: 949408
  • 博文数量: 245
  • 博客积分: 11429
  • 博客等级: 上将
  • 技术积分: 2662
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-15 00:16
文章存档

2011年(56)

2010年(174)

2009年(15)

分类: LINUX

2010-08-27 10:52:39

加固ssh 使其安全登录 并提供登录用户发送邮件提示。
1、修改端口,这也是常用的
    Port 22 这个你自己设置把
    #Protocol 2,1
    Protocol 2
2、修改ssh 为ssh 设置密钥
@su -     ##转换角色  到root用户
      #执行
    
@ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):  这里是密钥的存放的路径
Enter passphrase (empty for no passphrase):  这里输入你登录时的口令
Enter same passphrase again:  重复
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
7c:e4:36:8f:c0:83:1e:83:b0:3b:45:bb:8e:0c:07:d8 root@kaa  这里提示你密钥创建成功。
@进入到密钥的存放地址
 cd /root/.ssh/
  有如下文件
id_rsa  id_rsa.pub  
@创建ssh要用的密钥文件
 cat id_rsa.pub >> authorized_keys
 修改权限 保证安全
 chmod 400 authorized_keys
@将id_rsa  id_rsa.pub  下载到本地  删除服务器上这两个文件 保证安全
 修改sshd_config 文件
  取消注释
 RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys

 修改密码登录的方式
PermitEmptyPasswords no
PasswordAuthentication no
@重启sshd
我的登录工具是xshell 你连接的时候 直接提示要你找密钥了哦
给服务器增加了安全行哦

3、为了保证你了解都那些用户和ip登录到你的机器,你可以设置当有用户登录到你的服务器时给你发送一些用户信息资料,这样你就可以知道是不是你设置的用户了哦。
  vi ~/.bashrc
添加如下
 localip=`ifconfig eth0|awk '/inet/{print $2}'|cut -c 6-` 获取ip
      9 echo 'ALTERT - Root shell Access (Server Name) on:' `date` `who` | mail -s "Allert localhost ip is $localip :Roo        t Access from `who | cut -d "(" -f2 | cut -d")" -f1`" pang-kuo@163.com

# Source global definitions
     11 if [ -f /etc/bashrc ]; then
     12         . /etc/bashrc
     13 fi
阅读(1290) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-08-29 15:59:21

Download More than 1000 free IT eBooks: http://free-ebooks.appspot.com