SSH远程连接

概念
SSH全称secure shell,安全外壳协议(安全的shell),是一个计算机网络协议(默认端口号为22)。通过ssh协议可以在客户端安全(提供身份认证、信息加密)的远程连接LInux服务器或其他设备。

使用广泛的Xshell软件就是基于SSH协议远程连接。

SSH远程连接之后能干什么?

SSH远程连接之后,就可以像操作本地的机器一样操作远程机器。当需要操控的机器不在本地时就可以使用ssh协议远程连接操控。

1.SSH服务
安装nodejs服务
[root@localhost ~]# wget https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpm
[root@localhost ~]# yum -y install epel-release-7-14.noarch.rpm 
[root@localhost ~]# yum list | grep nodejs
[root@localhost ~]# yum -y install nodejs.x86_64
[root@localhost ~]# node -v
v16.20.2
nodejs是一个运行环境,和javajdk运行环境格式一样
简易服务器的环境
安装包管理器 npm node package manager
[root@localhost ~]# yum -y install npm
[root@localhost ~]# npm -v
8.19.4
npm 设置国内镜像
[root@localhost ~]# npm config set registry https://registry.npmmirror.com
安装vue的脚手架软件
[root@localhost ~]# npm install -g @vue/cli -g # -g全局安装
[root@localhost ~]# find / -name "vue"
/usr/local/bin/vue
/usr/local/lib/node_modules/@vue/cli/node_modules/vue
[root@localhost ~]# /usr/local/bin/vue -V  //查看版本
@vue/cli 5.0.8
使用vue脚手架创建一个前端项目
[root@localhost ~]# /usr/local/bin/vue create vuehtml000
[root@localhost ~]# tree vuehtml000/ #用树状显示
启动前端项目
[root@localhost ~]# 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@localhost ~]# yum -y install bash-completion-extras.noarch  #一个附加的Bash自动补全包,提供一些额外的自动补全功能
3.远程管理SSH服务
[root@llt ~]# 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@llt ~]# systemctl stop firewalld
[root@llt ~]# systemctl disable firewalld
[root@llt ~]# 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@llt ~]# 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/
woshizhangsan.txt
[root@y ~]# vim /etc/ssh/sshd_config 
17行 Port 9999
[root@y ~]# systemctl restart sshd
[zhangsan@y ~]$ ssh -llisi -p9999 192.168.1.11 //端口22更改为9999(如果不是22端口必须添加-p选项)
lisi@192.168.1.11's password: lisi
[lisi@y ~]$ 
安装pwgen密码生成工具
[root@y ~]# yum -y install pwgen.x86_64 
[root@y ~]# pwgen -cnBs1 10 1
 VwFN4jwVqP
pwgen 选项参数 长度 生成个数
密码中⾄少包含⼀个⼤写字⺟:-c or –capitalize
密码中不包含⼤写字⺟:-A or –no-capitalize
密码中⾄少包含⼀个数字:-n or –numerals
密码中不包含数字:-0 or –no-numerals
密码中⾄少包含⼀个特殊符号:-y or –symbols
⽣成完全随机密码:-s or –secure
密码中不包含歧义字符(例如1,l,O,0):-B or –ambiguous
使⽤SHA1 hash给定的⽂件作为⼀个随机种⼦:-H or –sha1=path/to/file[#seed]
在列中打印⽣成的密码:-C
不要在列中打印⽣成的密码,即⼀⾏⼀个密码:-1
不要使⽤任何元⾳,以避免偶然的脏话:-v or –no-vowels
4.scp命令
上传:
scp [选项] 本地⽂件路径 远程⽤户名@远程服务器的IP地址:远程⽂件存储路径
-r : 递归上传,主要针对⽂件夹
-P : 更换了SSH服务的默认端⼝必须使⽤-P选项
下载:
scp [选项] 远程⽤户名@远程服务器的IP地址:远程⽂件路径 本地⽂件存储路径
-r : 递归上传,主要针对⽂件夹
-P : 更换了SSH服务的默认端⼝必须使⽤-P选项
scp指定端口 -P大
ssh指定端口 -p小
[root@llt ~]# scp -P9999 /root/history.txt zhangsan@192.168.1.11:/code/
zhangsan@192.168.1.11's password: 
history.txt            

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值