ssh安全相关

1.更改端口号
    #vi /etc/ssh/sshd_config
    修改

Port 22

    为自定义端口

    PS:可能需要添加iptables规则。作用有限,仅仅增加端口扫描这一步而已

2.限制登录密码尝试次数
    #vi /etc/ssh/sshd_config

    定位到 MaxAuthTries  ,并修改

MaxAuthTries  3

    将默认的值改掉即可
    重启SSH

    PS:作用并不大,并没有限制ip的尝试次数.3次过后重新请求即可

2.限制ip
    #222.211.172.58
    1)hosts.allow 和 hosts.deny
    #vi /etc/hosts.allow

sshd : 192.168.0.100
sshd : 223.227.223.*

    #vi /etc/hosts.deny
 

sshd: ALL EXCEPT xxx.xxx.xxx.xxx
sshd: ALL EXCEPT xxx.xxx.xxx.xxx/24

    多个的话用逗号分隔:
 

sshd: 192.168.0.0/255.255.255.0,202.101.73.0/255.255.255.0

    数据包的校验顺序首先是/etc/hosts.allow,然后才是/etc/hosts/hosts.deny。

    2)#iptables规则
 

iptables -A INPUT -p tcp -s 192.168.1.2 --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j DROP

    3)配置sshd
    #vi /etc/ssh/sshd_config
    加入

Allowusers admin@172.16.2.188

    意思为
    只允许admin从172.16.2.188登陆
    如果是多个用户的话用空格分隔:

AllowUsers A B C

    PS:效果较好,但 IP 伪装一下还是呵呵;另外客户端为动态ip、异地访问时不方便

3.禁止root远程登陆,禁止密码登陆
    #vi /etc/ssh/sshd_config

PermitRootLogin yes -> no
PasswordAuthentication yes -> no

3.密钥对
    Client:
    创建公钥

$ ssh-keygen -b 2048 -t <dsa,rsa,ecdsa> -C  'your email@domain.com'


    复制公钥到到服务器

$ ssh-copy-id -i PATH_TO_PUBLIC_KEY.ssh/id_rsa.pub username@hostname

        OR

$ cat ~/.ssh/id_rsa.pub | ssh username@hostname "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"

        OR

$ scp ~/.ssh/id_rsa.pub username@hostname:~/ #将公钥文件复制至ssh服务器
$ ssh username@hostname #使用用户名和密码方式登录至ssh服务器
$ mkdir .ssh  #若.ssh目录已存在,可省略此步
$ cat id_rsa.pub >> .ssh/authorized_keys  #将公钥文件id_rsa.pub文件内容追加到authorized_keys文件

指定private_key登录:

ssh -i PATH_TO_PRIVATE_KEY/.ssh/id_rsa  username@hostname

    别名登录:
    $ vim ~/.ssh/config

Host www
    HostName www.host.com
    Port 22
    User root
    IdentityFile  ~/.ssh/id_rsa
    IdentitiesOnly yes

 

Host bbs
    HostName 192.168.0.111
    User anotheruser
    PubkeyAuthentication no

然后就可以用别名登录了:

$ ssh www
$ ssh bbs

 

应对 ssh 攻击可以尝试 ssh 蜜罐:

https://www.v2ex.com/t/306777?hmsr=toutiao.io&utm_medium=toutiao.io&utm_source=toutiao.io

参考网址:

http://blog.csdn.net/cnbird2008/article/details/8038926

http://blog.csdn.net/bravezhe/article/details/7302800

http://snowelf.iteye.com/blog/2163637

转载于:https://my.oschina.net/chaiko/blog/751332

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值