Secure SHell

学习笔记供以后参考复习

SSH的英文全称是Secure SHell。通过使用SSH,可以把所有传输的数据进行加密,这样数据就比较安全了,而且也能够防止DNS和IP欺骗。还有一个额外的好处就是传输的数据是经过压缩的,所以可以加快传输的速度。SSH有很多功能,它既可以代替telnet,又可以为ftp、pop、甚至ppp提供一个安全的“通道”(ftp、pop和telnet在本质上都是不安全的,因为它们在网络上用明文传送口令和数据,别有用心的人非常容易就可以截获这些口令和数据)

*ssh无密码登录要使用公钥与私钥。linux下可以用用ssh-keygen生成公钥/私钥对
下面我用CentOS 5.8做的实验机器A(192.168.1.100),B(192.168.1.200)。现想A通过ssh免密码登录到B。

1.在A机下生成公钥/私钥对。
[root@station100 ~]# ssh-keygen -t dsa   ---创建密钥
Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):  Enter
Enter passphrase (empty for no passphrase):  ---密码短语
Enter same passphrase again:  Enter
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
c8:6e:38:bf:7f:a3:e9:32:c2:64:3e:fc:b7:d8:4d:8a
[email protected]
它在/home/root下生成.ssh目录,.ssh下有id_rsa和id_rsa.pub。

2.把A机下的id_rsa.pub复制到B机下
[root@station100 ~]#
ssh-copy-id -i .ssh/id_rsa.pub [email protected]
15
The authenticity of host '192.168.100.200 (192.168.100.200)' can't be established.
RSA key fingerprint is c0:d1:9f:67:66:cf:5a:7f:b4:21:53:c8:8b:1a:c9:95.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.200' (RSA) to the list of known hosts.
[email protected]'s password:
Now try logging into the machine, with "ssh
'[email protected]'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[root@station100 ~]#

4.A机登录B机。
[root@station100 ~]# ssh 192.168.100.200
Last login: Tue Jun  5 23:48:05 2012 from 192.168.100.100
[root@station200 ~]#
5、想让A,B机无密码互登录,那B机以上面同样的方式配置即可

建立了ssh我们可以用一些基本操作:
copy 本地的档案到远程的机器上
[root@station100 ~]#
scp -p /etc/yum.conf [email protected]:/home
yum.conf                                      100%  379     0.4KB/s   00:00
[root@station100 ~]#
会将本地的 /etc/yum.conf 这个档案 copy 到 192.168.100.200:/home目录下。

copy远程机器上的档案到本地来
[root@station100 ~]#
scp -p [email protected]:/home/sql.txt /opt
sql.txt                                       100% 2816     2.8KB/s   00:00
[root@station100 ~]#

小结:登录的机子可有私钥,被登录的机子要有登录机子的公钥。这个公钥/私钥对一般在私钥宿主机产生。上面是用rsa算法的公钥/私钥对,当然也可以用dsa(对应的文件是id_dsa,id_dsa.pub)


**目前一般使用SSH比较流行,使用puttyy_ssh客户端工具可以实现远程登录管理;
一般很少用telnet因为telnet传递的全是明文方式,没有经过加密.安全性不高.
现在也有很多服务器不允许telnet登录了,只允许SSH登录.为了使服务器安全,看了一些文档,自己实验下面方法还是很好的,使用denyhosts以防止SSH被暴力破解
一、检查安装要求
首选检查Sshd是否支持 Tcpwrap,只有支持Tcpwrap才可以安装Denyhost
# ldd /usr/sbin/sshd |grep wrap
libwrap.so.0 => /usr/lib/libwrap.so.0 (0×00864000) //出现此信息时表示支持
再检查 Python的版本,Python2.3以上版本可以直接安装
# python -V
Python 2.4.3

均达到要求
denyhosts是用Python语言编写的一个程序,它会分析你的安全登陆日志文件,当发现重复的错误登录时就会记录IP到/etc/hosts.deny文件,然后自动屏蔽IP.功能非常的不错
我在虚拟机上测试:先下载 http://download.csdn.net/download/alex198211/2931109
DenyHosts-2.6.tar.gz然后上传到系统中,
#tar zxvf DenyHosts-2.6.tar.gz
#cd DenyHosts-2.6
#python setup.py install
cp /usr/share/denyhosts/denyhosts.cfg-dist /usr/share/denyhosts/denyhosts.cfg 拷贝配置文件
vim /usr/share/denyhosts/denyhosts.cfg
 
配置文件的修改
1、#日志文件,根据这个文件来判断
SECURE_LOG = /var/log/secure
2、#记录屏蔽的IP文件
HOSTS_DENY = /etc/hosts.deny
3、#多久清除屏蔽的IP,我设置一天
PURGE_DENY = 1d
4、#禁止的服务,我设置为全部,禁止登录SSH,也可以填ALL,包括SSH和FTP
BLOCK_SERVICE = SSH
5、#允许无效用户失败的数次
DENY_THRESHOLD_INVALID = 1
6、#允许普通用户失败的次数
DENY_THRESHOLD_VALID = 3
7、#允许root用户失败的次数
DENY_THRESHOLD_ROOT = 3
8、#是否做域名反解析
HOSTNAME_LOOKUP=NO
9、#管理员Email
ADMIN_EMAIL =
可以根据以上提示,对应的修改需要的就可以了。
 
设置启动脚本:
#cp /usr/share/denyhosts/daemon-control-dist /usr/share/denyhosts/daemon-control
#chown root /usr/share/denyhosts/daemon-control
#chmod 755 /usr/share/denyhosts/daemon-control
#ln -s /usr/share/denyhosts/daemon-control /etc/init.d/denyhosts
#chkconfig denyhosts on
启动denyhosts
#/etc/init.d/denyhosts

 

本文出自 “奔跑吧.少年” 博客,转载请与作者联系!

你可能感兴趣的:(数据,通道,的)