卡饭网 > linux > 正文

linux ssh安全加固方法

来源:本站整理 作者:梦在深巷 时间:2013-02-05 15:07:53

[root@localhost .ssh]# su - test1禁止root用户登录:

为增强安全,
先增加一个普通权限的用户:
#useradd *****
#passwd ******
//设置密码

生产机器禁止ROOT远程SSH登录:
#vim /etc/ssh/sshd_config


PermitRootLogin yes
改为
PermitRootLogin no
重启sshd服务
#service sshd restart

远程管理用普通用户*******登录,然后用 su - root 转换到root用户拿到最高权限。

禁止某个用户登录:
vim /etc/passwd

修改:lynn:x:500:500::/home/lynn:/bin/bash
为: lynn:x:500:500::/home/lynn:/sbin/nologin

修改 : #Port 22
为 : Port *****

使用密钥认证登录服务器:
1、以root用户登录服务器
2、 vim /etc/ssh/sshd_config

复制代码

代码如下:

Port 12345
StrictModes no
RSAAuthentication yes
PubkeyAuthentication yes
PermitEmptyPasswords no
PasswordAuthentication no

如果是给非root用户配置秘钥认证,下一步需要切换到相应的用户做操作:
[root@localhost .ssh]# su - test1

3、ssh-keygen -t rsa -b 1024
a、回车
b、键入密码

4、ls -a /root/.ssh 可以查看到生成两个文件
5、cat id_rsa.pub > authorized_keys
6、chmod 644 authorized_keys
7、rm -rf id_rsa.pub
8、ls -a /root/.ssh 现在就剩下两个文件,authorized_keys是公钥 id_rsa是密钥。
9、现在把id_rsa密钥烤出来。
10、注意先把id_rsa拷贝出来,然后再开一个ssh终端,在启动服务,以防密钥没有成功,ssh也登陆不进去了,也不能修改ssh配置了。
11、再开一个ssh终端,用于不成功的配置用。
12、/etc/init.d/ssh restart
13、如果用samba共享id_rsa文件,注意文件的权限。

相关推荐