SSH服务

1. SSH是安全的加密协议,用于连接Linux服务器

2. SSH默认端口是22,安全协议版本为SSH2,SSH1有漏洞

3. SSH服务端只要包含两个服务功能SSH远程连接和SFTP服务

4. Linux SSH客户端包含ssh远程连接命令以及远程拷贝scp命令等

   SSH2同时支持RSA和DSA密钥

SSH服务认证类型:基于口令的安全验证和基于密钥的安全验证

 查看是否安装服务

[root@m01 ~]# rpm -qa openssh openssl

openssh-5.3p1-94.el6.x86_64   (远程连接)

openssl-1.0.1e-15.el6.x86_64  (加密服务)

ssh服务优化:

[root@m01 ~]# cp /etc/ssh/sshd_config{,.ori}    #优化之前先备份

[root@m01 ~]# ll /etc/ssh/sshd*   #查看备份

[root@m01 ~]# vim /etc/ssh/sshd_config   #编辑配置文件

Port 52113    #修改端口,默认22端口                 

ListenAddress 172.16.1.61:52133   #只允许对应的ip登录

PermitRootLogin no    #禁止使用root用户远程登录

PermitEmptyPasswords no   #禁止空密码登录

GSSAPIAuthentication no   #解决Linux之间使用SSH远程连接慢的问题

#GSSAPIAuthentication yes

UseDNS no   #不使用DNS

[root@m01 ssh]# /etc/init.d/sshd reload  #平滑重启

快速修改和备份配置文件对比:

[root@m01 ssh]# sed -ir '13 iPort 52113\nPermitRootLogin no\nPermitEmptyPasswords no\nGSSAPIAuthentication no\nUseDNS no\n#ListenAddress 172.16.1.61:52133' /etc/ssh/sshd_config

[root@m01 ssh]# diff sshd_config.ori sshd_config

12a13,18

> Port 52113

> PermitRootLogin no

> PermitEmptyPasswords no

> GSSAPIAuthentication no

> UseDNS no

> #ListenAddress 172.16.1.61:52133

[root@m01 ssh]# /etc/init.d/sshd reload   #平滑重启

客户端测试:

[root@nfs01 ~]# ssh 10.0.0.61

ssh: connect to host 10.0.0.61 port 22: Connection refused #22端口拒绝访问

[root@nfs01 ~]# ssh -p52113 10.0.0.61

The authenticity of host '[10.0.0.61]:52113 ([10.0.0.61]:52113)' can't be established.

RSA key fingerprint is ac:ec:68:11:b5:07:aa:3f:3e:10:f8:17:f1:98:aa:0d.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '[10.0.0.61]:52113' (RSA) to the list of known hosts.

root@10.0.0.61's password:

Permission denied, please try again.  (root超级用户拒绝访问)

注:因为ssh服务已经设置禁止root超级用户远程登录,所有设置一个普通用户登录

[root@m01 ssh]# useradd ceshi

[root@m01 ssh]# echo 123456|passwd --stdin ceshi

 

如何防止SSH登录入侵小结:

1.用密钥登录,不使用密码登录

2.牤牛阵法:解决SSH安全问题

  1.防火墙封闭SSH,指定源IP限制(局域网、信任公网)

  2.开启SSH只监听本地内网IP

3.尽量不给服务器外网IP

 

ssh客户端命令:

ssh -p22 ceshi@10.0.0.61 [命令]   -p:指定端口

[root@nfs01 ~]# ssh -p52113 ceshi@10.0.0.61 

[root@nfs01 ~]# ssh -p52113 ceshi@10.0.0.61 /sbin/ifconfig eth0

 

[root@nfs01 ~]# ssh -p22 ceshi@10.0.0.61   

ssh: connect to host 10.0.0.61 port 22: Connection refused  #访问被拒绝

报错字符串对应可能的问题: no route to host #可能是防火墙影响

1. 可能是防火墙阻挡

2. 可能是连接的对方端口服务没开或端口改变

scp远程拷贝命令:

[root@nfs01 tmp]# scp -P52113 -rp /etc ceshi@10.0.0.61:/tmp   #将本地文件推向远端

[root@nfs01 tmp]# scp -P52113 -rp ceshi@10.0.0.61:/tmp/etc /data   #从远端拉到本地

 

scp知识小结:

1. scp是加密的远程拷贝,而cp仅为本地拷贝

2. 可以把数据从一台机器推送到另一台机器,也可以从其他服务器把数据拉回到本地执行命令的服务器

3. 每次都是全量完整拷贝,因此,效率不高,适合第一次拷贝用,如果需要增量拷贝,用rsync。

 

sftp服务及命令

[root@nfs01 ~]# sftp -oPort=52113 ceshi@10.0.0.61

Connecting to 10.0.0.61...

ceshi@10.0.0.61's password:

sftp> pwd  #可以使用命令行命令

Remote working directory: /home/ceshi

sftp> put /etc/hosts    #把/etc/hosts从客户端本地传到sftp服务器的家目录

Uploading /etc/hosts to /home/ceshi/hosts

/etc/hosts                               100%  325     0.3KB/s   00:00    

sftp> put /etc/hosts /tmp  #把/etc/hosts从客户端本地传到sftp服务器指定的目录/tmp

Uploading /etc/hosts to /tmp/hosts

/etc/hosts

sftp> get hosts

Fetching /home/ceshi/hosts to hosts #把hosts下载到本地连接前的目录

/home/ceshi/hosts                        100%  325     0.3KB/s

sftp命令小结:

1. Linux下连接命令 sftp -oPort=52113 ceshi@10.0.0.61

2. 上传put加客户端本地路径 put /etc/hosts

3. 下载get服务端的内容 get hosts  (Linux下载到本地连接前的目录),也可指定下载路径 get hosts /tmp

4. 连接到的远端家目录为默认目录,也可以切换到其他有权限的目录

 

章节小结:

1. ssh为加密的远程连接协议,相关软件有openssh和openssl

2. 默认端口22

3. 协议版本1.X和2.X,2.X更安全。

4. 服务端ssh远程连接服务,sftp服务。sshd守护进程,开机要自启动

5. ssh客户端包含ssh,scp,sftp命令

6. ssh安全验证方式:口令和密钥,这两种都是基于口令的,SSH密钥登录的原理

7. ssh服务安全优化,修改默认端口22,禁止root远程连接,禁止dns,SSH只监听内网IP

8. ssh密钥对,公钥(pubic key)在服务器端,就像锁,私钥(private key)在客户端,就像是钥匙

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值