有趣的远程访问——Linux学习笔记九

<< ——————第九单元—————— >>

1. 什么是openssh

   是一个提供远程访问控制的软件

 

2. 如何实现远程访问(cheese)

   ssh   远程主机用户@远程主机ip地址

【例】ssh root@172.25.254.1 -X(x代表可以访问桌面)

 

[root@foundation12 ~]# rm -fr /root/.ssh/    ##避免重复

[root@foundation12 ~]# ssh root@172.25.254.*** ##建立连接

The authenticity of host '172.25.254.221 (172.25.254.221)' can't be established.

ECDSA key fingerprint is eb:24:0e:07:96:26:b1:04:c2:37:0c:78:2d:bc:b0:08.

Are you sure you want to continue connecting (yes/no)? Yes ##建立安全传输key

Warning: Permanently added '172.25.254.221' (ECDSA) to the list of known hosts.

root@172.25.254.221's password: ##需要输入密码

Last login: Thu Sep 29 02:56:19 2016 from foundation12.ilt.example.com

[root@localhost ~]# killall -9 bash ##杀死了服务器端和客户端的bash

Connection to 172.25.254.221 closed.

[root@foundation12 ~]# ssh root@172.25.254.221 ##重新建立连接

[root@localhost ~]# cd /root/Desktop

[root@localhost Desktop]# touch file ##在桌面创建文件

ctrl +d |logout ##退出

[root@localhost ~]# vim /etc/motd ###设定登陆显示字符

 

 [root@localhost Desktop]# ssh-keygen ##生成密码

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Created directory '/root/.ssh'.

Enter passphrase (empty for no passphrase): ##密码为空

  /root/.ssh/id_rsa.                ## identification

  /root/.ssh/id_rsa.pub.         ##public key公钥(锁)存放地址

rsa--加密的一种算法

pub(public)--锁

The key fingerprint is:

5d:e6:9a:a9:ba:29:ed:81:d1:10:24:1d:ba:18:51:f4 root@localhost

The key's randomart image is:

+--[ RSA 2048]----+ ##2048位的RSA加密方式

|.o+o+.           |

| . +..           |

|. . E       o    |

| o . o   . +     |

|. . . . S . .    |

|     o     +     |

|    ...   +      |

|    . .o .       |

|     o=o.        |

+-----------------+

[root@localhost Desktop]# cd /root/.ssh/

[root@localhost .ssh]# ls

id_rsa(私钥)  id_rsa.pub(公钥)

Authorized_keys:公钥要开的锁

Know——hosts:连接的账户

[root@localhost .ssh]# ssh-keygen -i id_rsa.pub root@172.25.12.11

[root@localhost.ssh]# ssh-copy-id -i(指定公钥) id_rsa.pub(公钥) root@172.25.12.11  ##给本服务器加密,自己用的锁

[root@localhost .ssh]# scp id_rsa root@127.25.10.11:/root/.ssh/          ##向客户端发送密码

scp--远程复制的一个命令

:/root/.ssh/             --将上传的私钥存在改ip下的这个文件里

id_rsa                                        100% 1675     1.6KB/s   00:00    

 

 

3. 远程访问的命令

1) ssh-copy-id                     ####上传key的工具

2) -i                        ####指定使用的公钥

3) /home/test/.ssh/id_rsa.pub        #####使用公钥的名称

4) westos                     ####被管理的目标用户

5) 172.25.254.100                     ####被管理用户所在主机的ip

6) authorized_keys                     ###此文件在目标用户加目录的.ssh中,这个文件就是目标用户被加密的标识,文件内容为公钥内容。

 

2.sshd服务的简单配置

1) 执行vim /etc/ssh/sshd_config 进入命令模式            ###sshd服务的配置文件

2) 48行 PermitRootLogin yes|no                          ###是否允许超级用户通过sshd的认证

3) 78行 PasswordAuthentication yes|no               ###开启或关闭用户密码认证

4) AllowUsers student westos                         ###(可以登陆的用户)用户白名单,只允许在名单中出现的用户使用sshd服务

5) systemctl restart sshd                               ###重新加载配置,修改了sshd服务的配置文件后要重新加载

6) cd /etc/ssh                                              ##删除sshd_config文件

7) 执行yum reinstall openssh_server -y,重新安装ssh服务,如果被阻止,就执行yum install openssh_server -y。

    -y 进行重新安装

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值