阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

CentOS 7.1下SSH远程登录服务器详解

116次阅读
没有评论

共计 3115 个字符,预计需要花费 8 分钟才能阅读完成。

一、明文传输与加密传输

明文传输: 当我们的数据包在网络上传输的时候,以数据包的原始格式进行传输,别人很容易截获我们的数据包,得到我们的信息。

加密传输: 当两个主机之间传输信息或者是 A 主机远程控制 B 主机的时候,在两个主机传输数据包之前,加密过之后才通过网络传输过去。因此,就算有人截获了传输的数据包,也不知道传输的内容。

二、SSH(Secure Shell)简介

SSH 是建立在传输层和应用层上面的一种安全的传输协议。SSH 目前较为可靠,专为远程登录和其他网络提供的安全协议。在主机远程登录的过程中有两种认证方式:

CentOS 7.1 下 SSH 远程登录服务器详解

基于口令认证: 只要你知道自己帐号和口令,就可以登录到远程主机。所有传输的数据都会被加密,但是不能保证你正在连接的服务器就是你想连接的服务器。可能会有别的服务器在冒充真正的服务器,也就是受到“中间人”这种方式的攻击。

基于秘钥认证: 需要依靠秘钥,也就是你必须为自己创建一对秘钥,并把公用的秘钥放到你要访问的服务器上,客户端软件就会向服务器发出请求,请求用你的秘钥进行安全验证。服务器收到请求之后,现在该服务器你的主目录下寻找你的公用秘钥,然后吧它和你发送过来的公用秘钥进行比较。弱两个秘钥一致服务器就用公用秘钥加密“质询”并把它发送给客户端软件,客户端软件收到质询之后,就可以用你的私人秘钥进行解密再把它发送给服务器。

用这种方式,你必须要知道自己的秘钥口令。但是与第一种级别相比,地为主不需要再网络上传输口令

第二种级别不仅加密所有传送的数据,而且“中间人”这种攻击方式也是不可能的(因为他没有你的私人密匙)。但是整个登录的过程可能需要 10 秒。

三、启动 SSH 服务

3.1 注意:

CentOS 7.1 安装完之后默认已经启动了 ssh 服务我们可以通过以下命令来查看 ssh 服务是否启动。

3.2 查看 22 端口是否开放

#netstat -tnl

CentOS 7.1 下 SSH 远程登录服务器详解

3.3 查看 ssh 服务是否启动

#systemctl status sshd.service

CentOS 7.1 下 SSH 远程登录服务器详解

四、SSH 客户端连接服务器(口令认证)

4.1 直接连接到对方的主机,这样登录服务器的默认用户

$ssh 192.168.142.84
[admin@localhost ~]$ ssh 192.168.142.84
admin@192.168.142.84’s password:
Last login: Sat Jun 27 10:16:21 2015 from 10.66.85.46
Hello world
Welcome to this Linux ! 2015 年 06 月 27 日 星期六 10:54:54 CST

$exit 退出远程登录

4.2 使用账号登录对方主机 nii 用户

[admin@localhost ~]$ ssh nii@192.168.142.84

nii@192.168.142.84's password: 
Last login: Fri Jun 26 14:48:03 2015 from 192.168.142.35
Hello world

[nii@localhost ~]$ exit
登出
Connection to 192.168.142.84 closed.

五、SSH 客户端连接服务器(秘钥认证)

这种认证方式是比较安全的。

秘钥认证步骤:

  1. 生成公钥和私钥,生成的秘钥默认在 /root/.ssh/ 文件夹里面

    [root@localhost admin]# ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/root/.ssh/id_rsa):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /root/.ssh/id_rsa.
    Your public key has been saved in /root/.ssh/id_rsa.pub.
    The key fingerprint is:
    7e:fa:8c:c4:a5:0d:e0:db:8e:87:25:15:4a:d2:9b:0b root@localhost.localdomain
    The key’s randomart image is:
    +–[RSA 2048]—-+
    | . |
    | . o . |
    | o.+ . |
    | E.+.. |
    | ..oS . |
    | o=.= |
    | .+* o |
    | .+.= |
    | ..+.o |
    +—————–+

  2. 把生成的公钥发送到对方的主机上去,用 ssh-copy-id 命令,自动保存在对方主机的 /root/.ssh/authorized_keys 文件中去

    [root@localhost ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.142.84
    /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
    /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed – if you are prompted now it is to install the new keys
    root@192.168.142.84’s password:
    Hello world

    Number of key(s) added: 1

    Now try logging into the machine, with:“ssh >’root@192.168.142.84’”
    and check to make sure that only the key(s) you wanted were added.

    [root@localhost ~]# ssh 192.168.142.84 登录不需要密码了
    Last login: Sat Jun 27 10:01:07 2015 from 192.168.142.191
    Hello world

下面关于 SSH 相关的文章您也可能喜欢,不妨参考下:

Ubuntu 下配置 SSH 服务全过程及问题解决 http://www.linuxidc.com/Linux/2011-09/42775.htm

Ubuntu 14.04 下安装 Samba 及 SSH 服务端的方法 http://www.linuxidc.com/Linux/2015-01/111971.htm

SSH 服务远程访问 Linux 服务器登陆慢 http://www.linuxidc.com/Linux/2011-08/39742.htm

提高 Ubuntu 的 SSH 登陆认证速度的办法 http://www.linuxidc.com/Linux/2014-09/106810.htm

开启 SSH 服务让 Android 手机远程访问 Ubuntu 14.04  http://www.linuxidc.com/Linux/2014-09/106809.htm

如何为 Linux 系统中的 SSH 添加双重认证 http://www.linuxidc.com/Linux/2014-08/105998.htm

在 Linux 中为非 SSH 用户配置 SFTP 环境 http://www.linuxidc.com/Linux/2014-08/105865.htm

Linux 上 SSH 服务的配置和管理 http://www.linuxidc.com/Linux/2014-06/103627.htm

更多 CentOS 相关信息见 CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2016-03/129204.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计3115字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中