ssh: secure shell安全的shell,一种协议,监听tcp的22端口,安全的远程登录 (telnet 23端口,tcp)
Openssh:ssh协议的开源实现
服务器 主机
《-----------------
主机请求服务
------------------》
服务器使用自己的私钥加密一段数据
主机使用服务器的公钥解密
安装telnet 命令: ~]# yum install telnet-server 查看安装的包 ~]# yum list all telnet* 发现安装了两个包,telnet.x86_64,telnet-server.x86_64 ~]# chkconfig telnet on ~]# service xinetd restart ~]# ss -tnl 发现23号端口,已经起来了。
SSH协议版本:
v1 :基于CRC-32做MAC,不安全,易受中间人***
v2:双方主机协议选择安全的MAC方式,基于DH算法做秘钥交换,基于RSA或DSA算法实现身份认证。
两种方式的用户登录认证:v1 基于password v2 基于 key
OpenSSH
客户端组件:
ssh,配置文件:/etc/ssh/ssh_config 格式: ssh [user@]host [command] ssh [-l user host [command] -p prot :设置远程服务器监听的端口,尽量不要使用22号端口 -X :支持X11转发 -Y:支持信任的X11转发 Host PATTERN 基于秘钥的认证: 1.在客户端生成秘钥对 ssh -t rsa [-P ''] [-f "~/.ssh/id_rsa"] 注释: -p 后面加上密码,-f指定秘钥保存目录 2.把公钥传输到远程服务器对应用户的家目录 ssh-copy-id [-i [identity_file]] [user@]machine 3.测试 自加:以基于秘钥的认证,将centos6(MaGeCentos),192.168.1.103登陆到centos7,192.168.1.104 1.在.103主机的/root/.ssh目录下生产一对秘钥 ~]# ssh-keygen -t rsa Enter file in which to save the key (/root/.ssh/id_rsa): 默认把秘钥保存在/root/.ssh/id_rsa中,我直接选择默认,按下回车键 Enter passphrase (empty for no passphrase): 是否加密,我直接按下回车键,选择不加密 此时,~]# ls .ssh/ 会显示多出了两个文件,id_rsa id_rsa.pub 2.把公钥传输到远程服务器对应用户的家目录 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@192.168.1.104 3.测试 ssh root@192.168.1.104 以后就不用输入密码了 问题: Address 192.168.1.104 maps to bogon, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT! Now try logging into the machine, with "ssh 'root@192.168.1.104'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. 哈哈,以经找到解决方法,vim /etc/ssh/ssh_config 将GSSAPIAuthentication 值设为 no,即可解决此问题。 scp命令(跨主机的文件复制命令): scp [option] SRC... DEST/ 两种情况: PULL:scp [option] [user@]host:/PATH/FROM/SOMEFILE /PATH/TO/SOMEFILE PUSH: scp [option] /PATH/FROM/SOMEFILE [user@]host:/PATH/TO/SOMEFILE 选项:-r 递归复制(用于复制目录) -p 保持原文件的属性信息 -q 静默模式 -P PORT :指明remote host监听的端口 自加: PULL 机制演示: ~]# scp root@192.168.1.104:/etc/fstab /tmp/fstab.txt 把192.168.1.104下的/etc/fstab复制到192.168.1.103的/tmp/fstab.txt文件中 fstab 100% 501 0.5KB/s 00:00 PUSH机制演示: ~]# scp /etc/fstab root@192.168.1.104:/tmp/ 把192.168.1.103的/etc/fstab复制到192.168.1.104下的/tmp目录下 sftp : sftp [user@]host sftp> help 自加: ~]# sftp root@192.168.1.104
服务器端组件:
ssh 配置文件:/etc/ssh/sshd_config 常用参数: Port 22022 ListenAddress PermitRootLogin 后面建议改为NO UseDNS 改为no 限制可登陆用户的办法: 白名单 AllowUsers user1 user2 AllowGroups 自加:当修改配置文件后,例如修改监听端口为22022后,要重启服务,systemctl restart sshd.service (centos7上) 在Centos7上SElinux可能开启,使用~]# getenforce 查看是否开启,如果为Enforcing则表示开启;使用~]# setenforce 0 将其关闭。 在/etc/ssh/sshd_config 中 UseDNS yes这一项是是否进行DNS反解要改为no
转载于:https://blog.51cto.com/zhoushuyu/1699290