远程管理笔记

SSH两种认证⽅式

1、基于⽤户名密码的认证(精简版) JumpServer => ssh code@RealServer的IP地址

2、基于密钥对的认证 基于密钥对认证,也就是所谓的免密码登录,理解免密登录原理

一、配置yum源

JumpServer配置外⽹YUM源 => 阿⾥云

# mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOSBase.repo.backup
# wget -O /etc/yum.repos.d/CentOS-Base.repo
https://mirrors.aliyun.com/repo/Centos-7.repo
# yum clean all
# yum makecache

RealServer配置本地YUM源 => 把光盘镜像作为仓库(⾃建YUM仓库)

(1)挂载光盘

# mkdir /mnt/cdrom
# mount -o ro /dev/sr0 /mnt/cdrom
# chmod +x /etc/rc.local
# echo 'mount -o ro /dev/sr0 /mnt/cdrom' >> /etc/rc.local

(2)编写local.repo⽂件

# cd /etc/yum.repos.d
# vim local.repo
[local]
name=local yum
baseurl=file:///mnt/cdrom
enabled=1
gpgcheck=

二、openssh软件的安装

SSH服务底层的软件名称叫做openssh,open开源,ssh就是ssh服务。openssh属于C/S架构

软件,其拥有客户端与服务器端。

客户端:ssh

服务端:openssh-server

安装步骤:

# yum install openssh -y
# rpm -qa |grep openssh
或
# yum list installed |grep openssh

获取openssh⽣成的⽂件列表

# rpm -ql openssh-server
# 配置⽂件
/etc/ssh/sshd_config => ssh服务的主配置⽂件
/etc/sysconfig/sshd
# 服务管理脚本
/usr/lib/systemd/system/sshd.service => systemctl start sshd
# ⽂件共享服务 提供⽂件上传下载的服务
/usr/libexec/openssh/sftp-server
# ⼆进制⽂件程序⽂件
/usr/sbin/sshd
# 公钥⽣成⼯具
/usr/sbin/sshd-keygen
# man⼿册
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sftp-server.8.gz
/usr/share/man/man8/sshd.8.gz
# rpm -ql openssh-clients
# 客户端配置⽂件
/etc/ssh/ssh_config
# 远程copy命令 服务器间进⾏⽂件传输
/usr/bin/scp
# sftp客户端 上传下载⽂件操作
/usr/bin/sftp
/usr/bin/slogin
/usr/bin/ssh
/usr/bin/ssh-add
/usr/bin/ssh-agent
/usr/bin/ssh-copy-id
/usr/bin/ssh-keyscan
# 客户端man⼿册
4、查看并修改ssh服务端的配置⽂件
RealServer:禁⽌root账号远程登录
在配置⽂件设置permitRootlogin no,不允许root账户远程登录可以设置其他账户远程登录。
zhangsan
5、sshd服务管理
/usr/share/man/man1/scp.1.gz
/usr/share/man/man1/sftp.1.gz
/usr/share/man/man1/slogin.1.gz
/usr/share/man/man1/ssh-add.1.gz
/usr/share/man/man1/ssh-agent.1.gz
/usr/share/man/man1/ssh-copy-id.1.gz
/usr/share/man/man1/ssh-keyscan.1.gz
/usr/share/man/man1/ssh.1.gz
/usr/share/man/man5/ssh_config.5.gz
/usr/share/man/man8/ssh-pkcs11-helper.8.gz

三、查看并修改ssh服务端的配置⽂件

RealServer:禁⽌root账号远程登录

# man 5 sshd_config
PermitRootLogin => yes or no,默认为yes 代表允许通过root账号远程登录此服务器
# vim /etc/ssh/sshd_config
38⾏ PermitRootLogin no

在配置⽂件设置permitRootlogin no,不允许root账户远程登录可以设置其他账户远程登录。 zhangsan

四.SSH服务内容

安装nodejs服务

[root@web1 ~]# wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpm

[root@web1 ~]# yum -y install epel-release-7-14.noarch.rpm

[root@web1 ~]# yum list | grep nodejs

[root@web1 ~]# yum -y install nodejs.x86_64

[root@web1 ~]# node -v

v16.20.2

nodejs是一个运行环境,和javajdk运行环境格式一样

简易服务器的环境

安装包管理器 npm node package manager

[root@web1 ~]# yum -y install npm

[root@web1 ~]# npm -v

8.19.4

npm 设置国内镜像

[root@web1 ~]# npm config set registry https://registry.npmmirror.com

安装vue的脚手架软件

[root@web1 ~]# npm install -g @vue/cli -g # -g全局安装

[root@web1 ~]# find / -name "vue"

/usr/local/bin/vue

/usr/local/lib/node_modules/@vue/cli/node_modules/vue

[root@web1 ~]# /usr/local/bin/vue -V  //查看版本

@vue/cli 5.0.8

使用vue脚手架创建一个前端项目

[root@web1 ~]# /usr/local/bin/vue create vuehtml000

[root@web1 ~]# tree vuehtml000/ #用树状显示

启动前端项目

[root@web1 ~]# cd vuehtml000/

[root@web1 vuehtml000]# npm run serve

浏览器:192.168.1.11:8080/

构建项目

[root@web1 vuehtml000]# npm run build

[root@web1 vuehtml000]# cp -R ./dist/* /usr/share/nginx/html/

[root@web1 vuehtml000]# nginx

[root@web1 vuehtml000]# nginx -s reload

浏览器:192.168.1.11

2.SSH加密算法

对称加密

des 对称的公钥加密算法,安全低,数据传输速度快;使⽤同⼀个秘钥进⾏加密或解密

非对称加密 ras

rsa ⾮对称的公钥加密算法,安全,数据传输速度慢 ,SSH默认的加密算法

有2条密码本

公钥 用于加密 保障不是明文传输

私钥 用于解密 将加密的文件解析成明文

[root@web1 ~]# yum -y install bash-completion-extras.noarch  #一个附加的Bash自动补全包,提供一些额外的自动补全功能

3.远程管理SSH服务

[root@x ~]# ssh -lroot -p22 192.168.1.11

安装SSH服务:openssh、ssh-server、ssh-client

关闭防火墙与selinux

[root@y ~]# systemctl stop friewalld

[root@y ~]# systemctl disable firewalld

[root@y ~]# setenforce 0

[root@x ~]# systemctl stop firewalld

[root@x ~]# systemctl disable firewalld

[root@x ~]# setenforce 0

openssh软件安装

[root@y ~]# rpm -qa | grep openssh

openssh-clients-7.4p1-16.el7.x86_64

openssh-server-7.4p1-16.el7.x86_64

openssh-7.4p1-16.el7.x86_64

修改配置文件,不允许root账户远程登陆

# systemctl restart sshd => 重启

# systemctl status sshd => 状态

# systemctl stop sshd => 停⽌

# systemctl start sshd => 启动

# systemctl enable sshd => 开机⾃启动

# systemctl disable sshd => 开机不⾃启

# ps -ef |grep sshd => 进程/netstat -tnlp |grep sshd => 端⼝/ ss -naltp |grep sshd

重启ssh服务

# systemctl restart sshd或# systemctl reload sshd

restart与reload的本质区别:

① restart其实相当于stop然后在start

② reload不停⽌现有业务,只是重新加载sshd对应的配置⽂件

[root@y ~]# vim /etc/ssh/sshd_config

38行 PermitRootLogin no

[root@y ~]# systemctl restart sshd

[root@x ~]# ssh -lzhangsan 192.168.1.11

zhangsan@192.168.1.11's password: zhangsan

[zhangsan@y ~]$

[root@y ~]# groupadd code //创建附属组

[root@y ~]# usermod -g code zhangsan  //将zhangsan添加到附属组

[root@y ~]# usermod -g code lisi

[root@y ~]# mkdir /code/

[root@y ~]# chmod -R g+w /code/ #添加修改权限

[zhangsan@y ~]$ touch /code/woshizhangsan.txt

[zhangsan@y ~]$ ls /code/

四、SSH免密登录解决⽅案

(1)① 回顾基于⽤户名密码的认证⽅式

(2)基于密钥对(公钥与私钥)的认证⽅式 => 免密登录

A主机 => JumpServer,B主机 => RealServer

第⼀步:在A主机(JumpServer)⽣成⼀个密钥对(公钥和私钥)

第⼆步:把A主机的公钥通过⽹络拷⻉到B主机(RealServer)上,然后把其内容追加到B主机 的~/.ssh/authorized_keys

第三步:由A主机(JumpServer)向B主机(RealServer)发起登录请求,然后直接在B主机 上进⾏公钥⽐对(判断A主机的公钥是否已经存储在B主机的authorized_keys⽂件中),如果 存在且正确,则⽣成⼀个随机的字符串(如itcast),然后使⽤A主机的公钥对其加密得到加密 的后字符串(如dXdh,34njasz!z.)

第四步:通过⽹络,由B主机讲刚才⽣成的加密后的字符串传输给主机A,主机A接收到加密后 的字符串以后,使⽤⾃⼰本地存储的私钥进⾏解密操作(得到itcast)

第五步:把解密得到的itcast发送到B主机,然后验证与刚才⽣成的字符串是否⼀致,如果⼀ 致,返回登录成功。反之,则返回登录失败。 到此免密登录全部完成!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值