博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux系统中的远程登陆服务
阅读量:3962 次
发布时间:2019-05-24

本文共 5151 字,大约阅读时间需要 17 分钟。

Linux系统中的远程登陆服务

一.实验环境

client:westos_client.westos.com172.25.254.10server:westos_node1.westos.com172.25.254.20ifconfig                   ##查看 ip 地址nm-connection-editor       ##设定 ip 地址hostnamectl set-hostname   ##设定主机名称

二.Openssh 服务的基本信息

Openssh# 1.作用: #在企业中的运维工作,不是 1v1 的运维运维工程师基本都是 1vN在运维工程师对服务器进行管理时需要通过网络登陆远程主机需要通过网络在远程主机中开启 shell 来进程操作远程主机必须提供这样的开启 shell 的方式以上的需求由 openssh 服务来提供远程主机中安装了 openssh 并开启了这个程序那么我们就可以通过网络来连接这台主机了# 2.软件包名称 #openssh-server# 3.服务名称#sshd# 4.客户端 #sshssh 172.25.254.20 -l root   # 172.25.254.20 远程主机 ip                            # -l login 登陆                            # root 远程主机的超级用户[root@westos_client ~]# ssh 172.25.254.20 -l rootThe authenticity of host '172.25.254.20 (172.25.254.20)' can't be established.ECDSA key fingerprint is SHA256:+5Ikt8ZExrRdLzOg19xsL5PhAYPt8GB7umvLcSF/dlM.Are you sure you want to continue connecting (yes/no)? yes  #建立关系Warning: Permanently added '172.25.254.20' (ECDSA) to the list of known hosts.root@172.25.254.20's password: ##输入远程主机密码Activate the web console with: systemctl enable --now cockpit.socketLast login: Sat Apr 25 09:02:58 2020[root@westos_node1 ~]#         ##登陆成功# 5.sshd 服务端口 #22/tcp# 6.配置文件 #/etc/ssh/sshd_config

三.Openssh 服务的 key 认证

# 1.用户密码认证 (对称加密)#* 密码容易泄漏* 容易忘记# 2.密钥认证 (非对称加密)#* 安全* 不会忘记密码# 3.建立 key 认证的方式 #* 建立 key 文件172.25.254.10 主机[root@westos_client ~]# ssh-keygen ##建立认证 key 文件Generating public/private rsa key pair.Enter file in which to save the key (/root/.ssh/id_rsa): ##加密字符保存位置Enter passphrase (empty for no passphrase):      ##key 认证密码,通常设定为空Enter same passphrase again:                     ##重复 key 认证密码Your identification has been saved in /root/.ssh/id_rsa.Your public key has been saved in /root/.ssh/id_rsa.pub.* 上传公钥 (加密远程主机)[root@westos_client ~]# ssh-copy-id  -i  /root/.ssh/id_rsa.pub  root@172.25.254.20#ssh-copy-id  上传密钥命令#-i           指定公钥#/root/.ssh/id_rsa.pub 公钥名称#root         远程主机被加密用户#@            分割符#172.25.254.20 远程主机地址/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that arealready 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 keysroot@172.25.254.20's password:   ##远程主机密码Number of key(s) added: 1Now try logging into the machine, with:"ssh 'root@172.25.254.20'"and check to make sure that only the key(s) you wanted were added.* 测试172.25.254.10 主机中 1.ssh root@172.25.254.20    ##免密连接2.mv /root/.ssh/id_rsa* /mnt  3.reboot4.ssh root@172.25.254.20    ##因为密钥被移除所以不能免密5.mv /mnt/id_rsa /root/.ssh ##重新恢复密钥6.ssh root@172.25.254.20    ##免密连接

四.Openssh 服务的安全配置

# 1.端口修改 #vim /etc/ssh/sshd_config17 port 22 -----> port 1111测试:[root@westos_client ~]# ssh 172.25.254.20 -l rootssh: connect to host 172.25.254.20 port 22: Connection refused #默认连接被拒绝[root@westos_client ~]# ssh 172.25.254.20 -l root -p 1111      #指定的的端口连接Activate the web console with: systemctl enable --now cockpit.socketLast login: Sat Apr 25 11:05:31 2020 from 172.25.254.10[root@westos_node1 ~]##2. 端口绑定 #vim /etc/ssh/sshd_config19 #ListenAddress 0.0.0.0  ----> ListenAddress 172.25.254.20测试:在 172.25.254.20 主机中参数未发生变化:ssh 172.25.254.20 -l root   #可以ssh 127.0.0.1 -l root       #可以参数发生变化ssh 172.25.254.20 -l root   #可以ssh 127.0.0.1 -l root       #拒绝#3.密码认证的关闭#vim /etc/ssh/sshd_config73 PasswordAuthentication no     ##禁用密码认证测试:172.25.254.10 有密钥172.25.254.20 无密钥172.25.254.10 ----->  ssh root@172.25.254.20    ##可以登陆172.25.254.20 ----->  ssh root@172.25.254.20    ##可以输入密码 参数根改并重启服务后172.25.254.10 ----->  ssh root@172.25.254.20    ##可以登陆172.25.254.20 ----->  ssh root@172.25.254.20    ##不可输入密码直接被拒绝#4. sshd 服务的用户控制#建立实验素材在服务器中:172.25.254.20useradd westosuseradd leeecho lee| passwd --stdin westosecho lee| passwd --stdin lee操作完成系统中存在至少 3 个用户用户      密码root     leewestos   leelee      lee#root 用户的访问控制vim /etc/ssh/sshd_config46 PermitRootLogin yes --->PermitRootLogin no   #禁止 root 用户使用 ssh 进行认证实验:172.25.254.20:ssh 172.25.254.20 -l root ##默认输入正确秘密可以完成认证修改参数后ssh 172.25.254.20 -l root ##输入正确密码仍然不能登陆#用户黑名单 (默认可以登陆,名单中的用户被禁止)vim /etc/ssh/sshd_configDenyUser lee              ##lee 用户不能使用 sshd 服务实验:172.25.254.20:ssh 172.25.254.20 -l lee     ##默认可以登陆ssh 172.25.254.20 -l westos  ##可以登陆修改参数后ssh 172.25.254.20 -l westos  ##可以登陆ssh 172.25.254.20 -l lee     ##不可以登陆#用户白名单 (默认不可以登陆,名单中的用户被允许)vim /etc/ssh/sshd_configAllowUsers westos            ##westos 用户可以使用 sshd 服务,默认用户被禁止实验:172.25.254.20:ssh 172.25.254.20 -l lee     ##默认可以登陆ssh 172.25.254.20 -l westos  ##可以登陆ssh 172.25.254.20 -l root    ##可以登陆修改参数后ssh 172.25.254.20 -l westos  ##可以登陆ssh 172.25.254.20 -l lee     ##不可以登陆ssh 172.25.254.20 -l root    ##不可以登陆

五.远程执行命令

172.25.254.20 登陆模式选择第二个(X11 模式)172.25.254.10:ssh 172.25.254.20 -l root    ##此方法登陆时不能调用远程主机的图形命令ssh -X 172.25.254.20 -l root ##当前登陆可以调用图形 -X 代表启用 x11 图形连接ssh 172.25.254.20 -l root touch /root/Desktop/westosfile{
1..10} #直接执行命令在远程主机中ssh 172.25.254.20 -l root -o StrictHostKeyChecking=no ##在连接主机时不检测 HOSTKEY ##(屏蔽 yes、no 的输入)

六.sshd 登陆信息修改

#172.25.254.20:vim /etc/motd      ##在此文件中有什么字符在 ssh 登陆时就可以看到什么字符

转载地址:http://qjhzi.baihongyu.com/

你可能感兴趣的文章
第七颗头骨 & 忘魂花 凤凰
查看>>
李小龙哲学之言
查看>>
[心情] 如果有一天
查看>>
[Linux] 常用 linux 系统命令及维护备忘
查看>>
[Linux] 关于 Ext4 HowTo
查看>>
[杂记] 新年物语&关于Mysql引擎性能测试
查看>>
[心得] 近期更新&关于Infobright
查看>>
[杂记] 流量统计 & 短信接口
查看>>
[中间件] 消息处理利器 ActiveMQ 的介绍 & Stomp 协议的使用
查看>>
[设计] 原型界面设计利器 Balsamiq Mockups 推荐
查看>>
[闲话] 在西方的程序员眼里,东方的程序员是什么样的
查看>>
[管理] 成功之路的探寻 —— “三力” 理论
查看>>
[连载] Socket 深度探索 4 PHP (一)
查看>>
[无线] Android 系统开发学习杂记
查看>>
[无线] 浅析当代 LBS 技术
查看>>
[杂感] 缅怀乔布斯
查看>>
[无线] 让Android支持cmwap上网
查看>>
[无线] AndroidManifest.xml配置文件详解
查看>>
[移动] Mosquitto简要教程(安装/使用/测试)
查看>>
[HTML5] 关于HTML5(WebGL)的那点事
查看>>