Administrator
发布于 2023-11-13 / 19 阅读
0
0

Ubuntu Install

设置root密码

sudo passwd
或者
sudo passwd root

安装vim

apt install vim

设置静态固定IP

利用netplan,是设置网络

refer to : https://zhuanlan.zhihu.com/p/445717663

cd /etc/netplan

vim 01-netcfg.yaml
# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens33:
      dhcp4: false
      addresses: [192.168.150.110/24]
      gateway4: 192.168.150.1
      nameservers:
        addresses: [114.114.114.114,8.8.8.8]
# 配置的网络生效
netplan apply

在 Ubuntu 上启用 SSH

refer to : https://zhuanlan.zhihu.com/p/145763789

apt install openssh-server

systemctl status ssh

ufw allow ssh

UFW防火墙

refer to : https://zhuanlan.zhihu.com/p/139381645

# 查看ufw的状态
ufw status verbose

# 启用ufw
ufw enable

# 打开端口
ufw allow port_number/protocol

ufw allow 80/tcp
# 当没有给出协议的时候,UFW 同时创建tcp和udp的规则。


# 打开端口范围
ufw allow 7100:7200/tcp

# 重启防火墙以生效
ufw reload


# 查看端口开放情况
ufw status verbose

# 查看各端口,分别被哪个应用程序使用
apt install net-tools

netstat -ntlp

软件源替换

refer to : https://zhuanlan.zhihu.com/p/421178143

cp /etc/apt/sources.list /etc/apt/sources.list.bak

cd /etc/apt
vim sources.list

在文件顶部,添加以下内容:

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
# deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
apt update

设置时区

# 查看时区
timedatectl status

# 设置时区
timedatectl set-timezone Asia/Shanghai

# 更新系统时间
systemctl restart systemd-timesyncd

同步时间—Chrony

refer to : https://chrony-project.org/doc/4.4/chrony.conf.html

apt install chrony
vim /etc/chrony/chrony.conf


#注释掉原来的ubuntu的ntp,指定aliyun的ntp

#pool ntp.ubuntu.com        iburst maxsources 4
#pool 0.ubuntu.pool.ntp.org iburst maxsources 1
#pool 1.ubuntu.pool.ntp.org iburst maxsources 1
#pool 2.ubuntu.pool.ntp.org iburst maxsources 2

pool ntp.aliyun.com iburst
pool ntp1.aliyun.com iburst



# 重启chronyd服务
systemctl restart chronyd

# 查看,是否设置了开机自启动
systemctl is-enabled chronyd

# 设置开机自启动
systemctl enable chronyd

# 强制同步时钟
chronyc -a makestep

# 重新查看时间
date
Wed Nov  8 09:21:18 CST 2023

设置允许以root用户登录

vim /etc/ssh/sshd_config

找到Authentication,修改成以下内容:

# Authentication:
LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
MaxAuthTries 6
MaxSessions 10
# 重启系统
reboot

上面各参数的含义,解释如下:

LoginGraceTime 允许一次登录花费 30 秒;如果用户花费的时间超过 30 秒,就不允许他访问,必须重新登录。

MaxAuthTries 把错误尝试的次数限制为 3 次,3 次之后拒绝登录尝试。

上面的 Protocol 2 行禁止使用比较弱的协议。

PermitRootLogin 不允许任何人作为根用户登录,这会让黑客攻击更困难。

常用命令

apt-get 和 apt的区别

WARNING : apt does not have a stable CLI interface.

这两个命令场景分化了,apt命令是给人用的,apt-get是给脚本自动化用的

dpkg(底层工具)->apt-get(上层工具)->apt(apt-get的再封装)

Apt,可以基本解决依赖问题并检索需要的软件包,可与dpkg一起工作。Apt很强大,主要在命令行(控制台/terminal)下使用。但是,也有很多GUI/图形化工具,让使用者不必接触命令行。

简单来说就是:apt = apt-get、apt-cache 和 apt-config 中最常用命令选项的集合。

理解包管理系统

不同的 Linux 发行版使用不同的包管理系统,一般而言,大多数发行版分别属于两大包管理技术阵营: Debian 的”.deb”,和红帽的”.rpm”。

**dpkg 😗*这个机制最早是由Debian Linux社群所开发出来的﹐通过dpkg 的机制,

Debian提供的软件就能够简单的安装起来,同时还能提供安装后的软件信息。只要是衍生于Debian 的其他Linux distributions 大多使用dpkg这个机制来管理软件的,包括B2D, Ubuntu等等。

**RPM:**这个机制最早是由Red Hat这家公司开发出来的﹐后来实在很好用﹐因此很多distributions 就使用这个机制来作为软件安装的管理方式。包括Fedora, CentOS, SuSE等等知名的开发商都是使用RPM。

包管理系统:

发行版 底层工具 上层工具
Debian-style dpkg apt-get 、apt
RedHat 、Fedora、Rocky Linux rpm yum

软件包管理系统通常由两种工具类型组成:底层工具用来处理这些任务,比方说安装和删除软件包文件, 和上层工具,完成元数据搜索和依赖解析。

dpkg和apt-get的区别

dpkg:用来安装.deb文件时,不会解决模块的依赖关系,且不会关心ubuntu的软件仓库内的软件,可以用于安装本地的deb文件。

apt-get:会解决和安装模块的依赖问题,并会咨询软件仓库,但不会安装本地的deb文件,apt-get是建立在dpkg之上的软件管理工具。

apt 命令 取代的apt-get命令 命令的功能

apt install | apt-get install | 安装软件包

apt remove | apt-get remove | 移除软件包

apt purge | apt-get purge | 除软件包及配置文件

apt update | apt-get update | 刷新存储库索引

apt upgrade | apt-get upgrade | 升级所有可升级的软件包

apt autoremove | apt-get autoremove | 自动删除不需要的包

apt full-upgrade | apt-get dist-upgrade | 在升级软件包时自动处理依赖关系

apt search | apt-cache search | 搜索应用程序

apt show | apt-cache show | 显示安装细节



评论