[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# ls /etc/yum.repos.d/
bak.tar.gz CentOS-Base.repo dvd.repo epel.repo epel-testing.repo
[root@localhost ~]# yum list | grep nodejs // 找到nodejs.x86_64的安装包
[root@localhost ~]# yum -y install nodejs.x86_64 //直接安装
[root@localhost ~]# node -v
v16.20.2
简易服务器环境
安装包管理器 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
[root@localhost ~]#
安装vue的脚手架软件
[root@localhost ~]# npm install @vue/cli -g //指定安装
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated @babel/plugin-proposal-optional-chaining@7.21.0: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.
npm WARN deprecated @babel/plugin-proposal-nullish-coalescing-operator@7.18.6: This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.
... ...
74 packages are looking for funding
run `npm fund` for details
npm notice
npm notice New major version of npm available! 8.19.4 -> 10.8.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.2
npm notice Run npm install -g npm@10.8.2 to update!
npm notice
[root@localhost ~]#
[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
在当前目录创建vuehtml000 目录,程序员就可以在这个文件中开发前端页面
将vue项目做成一个前段项目
[root@localhost vuehtml000]# npm run build
# 在vue项目的目录中找到刚刚生成的dist目录
[root@localhost vuehtml000]# ls
babel.config.js jsconfig.json package.json public src
dist node_modules package-lock.json README.md vue.config.js
[root@localhost vuehtml000]# ls ./dist/
css favicon.ico index.html js
[root@localhost vuehtml000]#
将这些静态文件部署到nginx的HTML
[root@localhost ~]# mkdir /usr/share/nginx
[root@localhost ~]# mkdir /usr/share/nginx/html
[root@localhost vuehtml000]# find / -name "html" -type d
/root/Python-3.12.4/Lib/html
/var/www/html
/usr/lib64/python2.7/site-packages/lxml/html
/usr/share/doc/pam-1.1.8/html
/usr/share/doc/pcre-devel-8.32/html
/usr/share/doc/sgml-common-0.6.3/html
/usr/share/doc/postgresql-9.2.23/html
/usr/share/doc/python-kitchen-1.1.1/html
/usr/share/doc/neon-0.30.0/html
/usr/local/python3124/lib/python3.12/html
[root@localhost vuehtml000]# cp -R ./dist/* /usr/share/nginx/html
[root@localhost vuehtml000]#
启动nginx
[root@localhost vuehtml000]# netstat -lntup | grep sshd
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1096/sshd
tcp6 0 0 :::22 :::* LISTEN 1096/sshd
[root@localhost vuehtml000]#
ssh 商用收费的对安全负责
当前系统默认安装的是
[root@localhost vuehtml000]# systemctl stop sshd //停用ssh,Xshell断开
关闭防火墙和SElinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
[root@localhost ~]#
检查epel
[root@localhost ~]# ls /etc/yum.repos.d/
bak.tar.gz CentOS-Base.repo dvd.repo epel.repo epel-testing.repo
[root@localhost ~]# yum -y install openssh
已加载插件:fastestmirror
... ...
[root@localhost ~]# yum -y install openssh-clients
查找主配置文件
[root@localhost ~]# ls /etc/ssh
moduli ssh_host_ecdsa_key ssh_host_ed25519_key.pub
ssh_config ssh_host_ecdsa_key.pub ssh_host_rsa_key
sshd_config ssh_host_ed25519_key ssh_host_rsa_key.pub
[root@localhost ~]#
[root@localhost ~]# rpm -ql openssh-clients
/etc/ssh/ssh_config
/usr/bin/scp
/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
修改主配置文件/etc/ssh/sshd_config
(man 5 sshd_config 使用手册查看),不允许root远程登录
[root@localhost ~]# vim /etc/ssh/sshd_config
38 PermitRootLogin no
[root@localhost ~]# systemctl restart sshd
添加用户和组
[root@localhost ~]# useradd yulan
[root@localhost ~]# passwd yulan
更改用户 yulan 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# useradd lisi
[root@localhost ~]# passwd lisi
更改用户 lisi 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。
[root@localhost ~]# su
[root@localhost ~]# ls -l /home/
总用量 4
-rw-r--r--. 1 root root 233 7月 15 16:04 bak.tar.gz
drwx------. 4 lisi lisi 106 7月 17 localhost:52 lisi
drwx------. 2 mm mm 62 4月 11 2018 mm
drwx------. 2 user1 user1 62 7月 11 10:20 user1
drwx------. 2 user2 user2 81 7月 11 10:29 user2
drwx------. 2 user3 user3 81 7月 11 10:41 user3
drwx------. 3 yulan yulan 115 7月 17 localhost:40 yulan
[root@localhost ~]# mkdir /code
[root@localhost ~]# groupadd code
[root@localhost ~]# usermod -g code yulan //添加到组
[root@localhost ~]# usermod -g code lisi
[root@localhost ~]#
[root@localhost ~]# chgrp -R code /code/
[root@localhost ~]# chmod -R g+w /code/ //给code组写的权限
[yulan@localhost ~]$ touch /opt/woshiyulantouch: 无法创建"/opt/woshiyulan": 权限不够[yulan@localhost ~]$ touch /code/woshiyulan //成功创建
[lisi@localhost ~]$ touch /code/woshiyulan.txt //成功创建[lisi@localhost ~]$
更改配置
[root@localhost ~]# vim /etc/ssh/sshd_config
17 Port 9999
[root@localhost ~]# systemctl restart sshd //重启ssh服务
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
[root@localhost ~]#
ssh连接服务器,如果服务器端口是22 ,可以不用添加 -p 端口;如果服务器端口是其他,一定要 -p 加端口
[root@localhost ~]# ssh -lyulan 192.168.2.localhost //不指定端口无法连接
ssh: connect to host 192.168.2.localhost port 22: Connection refused
[root@localhost ~]# ssh -lyulan 192.168.2.localhost -p9999 //指定端口9999 成功
安装密码生成工具
[root@localhost ~]# yum -y install pwgen.x86_64
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 16 kB 00:00
* base: mirrors.aliyun.com
* epel: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00
extras | 2.9 kB 00:00
mnt | 3.6 kB 00:00
updates | 2.9 kB 00:00
正在解决依赖关系
--> 正在检查事务
---> 软件包 pwgen.x86_64.0.2.08-1.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=============================================================================
Package 架构 版本 源 大小
=============================================================================
正在安装:
pwgen x86_64 2.08-1.el7 epel 26 k
事务概要
=============================================================================
安装 1 软件包
总下载量:26 k
安装大小:42 k
Downloading packages:
pwgen-2.08-1.el7.x86_64.rpm | 26 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : pwgen-2.08-1.el7.x86_64 1/1
验证中 : pwgen-2.08-1.el7.x86_64 1/1
已安装:
pwgen.x86_64 0:2.08-1.el7
完毕!
[root@localhost ~]# pwgen -cnBs1 10 1 //生成密码
77ukWnbwm9
[root@localhost ~]#
scp 指定端口 -P (大写)
ssh 指定端口 -p (小写)
默认端口22 ,不需要指定
查看用户:
[root@localhost ~]# who
root tty1 2024-07-17 09:30
root pts/0 2024-07-17 09:32 (192.168.2.2)
root pts/1 2024-07-17 09:56 (192.168.2.2)
yulan pts/3 2024-07-17 15:24 (192.168.2.2)
[root@localhost ~]#
[root@localhost ~]# pkill -kill -t pts/3 //杀死用户yulan
[root@localhost ~]# who
root tty1 2024-07-17 09:30
root pts/0 2024-07-17 09:32 (192.168.2.2)
root pts/1 2024-07-17 09:56 (192.168.2.2)
[root@localhost ~]#
生成密钥:
[root@localhost ~]# su yulan
[yulan@localhost root]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/yulan/.ssh/id_rsa):
Created directory '/home/yulan/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/yulan/.ssh/id_rsa.
Your public key has been saved in /home/yulan/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:1wWpTipdICDGFRdzQtNRn/5JUqlmRMZeDm4iLD7Umz4 yulan@localhost
The key's randomart image is:
+---[RSA 2048]----+
| .o.++Booo..+. |
| ... ..=o ++o.. |
| + . ++++ |
| o + =+++. |
| o oSO.oB . |
| + =..o + . |
| + o |
| E |
| . |
+----[SHA256]-----+
[yulan@localhost root]$ cd
[yulan@localhost ~]$ ls ./.ssh/
id_rsa id_rsa.pub
[yulan@localhost ~]$ ls ./.ssh/ -l
总用量 8
-rw-------. 1 yulan code 1679 7月 17 16:17 id_rsa //私钥
-rw-r--r--. 1 yulan code 390 7月 17 16:17 id_rsa.pub //公钥
[yulan@localhost ~]$
把公钥传输:
[yulan@localhost ~]$ ssh-copy-id root@192.168.2.localhost
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/yulan/.ssh/id_rsa.pub"
/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.1
68.2.localhost's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh 'root@192.168.2.localhost'"
and check to make sure that only the key(s) you wanted were added.
[yulan@localhost ~]$
[yulan@localhost ~]$ ssh -lroot 192.168.2.localhost //不用密码直接登录
Last login: Wed Jul 17 11:31:58 2024 from 192.168.2.2
[root@localhost ~]# ls ./.ssh/
authorized_keys known_hosts
[root@localhost ~]# exit
登出
Connection to 192.168.2.localhost closed.
[yulan@localhost ~]$ exit
exit
[root@localhost ~]# ls /home/yulan/.ssh/ //只有yulan用户有免密登录文件
authorized_keys id_rsa id_rsa.pub known_hosts