Linux基础配置

本文最后更新于:2025年7月15日 晚上

前言

本文章对各Linux系统的基础配置(代理,apt源)进行记录,以防不时之需。

修改系统时区

默认时区是UTC,使用以下命令修改时区为亚洲(CST):

1
sudo timedatectl list-timezones
1
sudo timedatectl set-timezone Asia/Shanghai
1
date

apt代理

临时代理:

1
2
3
export http_proxy=http://ip:port

sudo apt-get update

永久代理:

修改/etc/apt/apt.conf(或者/etc/envrionment),在适当位置新增以下内容:

1
2
3
Acquire::http::proxy "http://ip:port/";
Acquire::ftp::proxy "ftp://ip:port/";
Acquire::https::proxy "https://ip:port/";

命令行单次代理:

1
sudo apt-get -o Acquire::http::proxy="http://ip:port/" update

sudo代理

使用export对系统进行临时代理时,如果执行sudo命令,这种代理方式会失效,就需要使用以下方法进行设置,启用sudo代理。[1]

1
2
3
sudo visudo
or
sudo vim /etc/sudoers

在文件适当位置新增以下字段:

1
Defaults        env_keep += "http_proxy https_proxy ftp_proxy no_proxy"

磁盘扩容

当磁盘不足时可以使用以下方法快速完成磁盘扩容操作。[2]

  1. 安装所需工具

    1
    sudo apt-get install gparted
  2. 打开应用程序GParted

    磁盘扩容的前提是有一块未分配的磁盘空间才行。

    对需要扩容的磁盘右键选择调整大小

    调整扩容后的磁盘大小

    调整好之后点击工具栏的 ✔应用全部操作 即可完成磁盘扩容。

开启SSH

对于桌面版的Linux系统,默认都是关闭SSH服务的,需要执行以下操作材料开始SSH远程访问。[3]

  1. 安装SSH服务器及客户端

    1
    sudo apt install openssh-server openssh-client
  2. 配置SSH

    1
    sudo nano /etc/ssh/ssh_config

    启用:PasswordAuthentication yes

    1
    sudo nano /etc/ssh/sshd_config

    启用:PermitRootLogin yes

  3. 重启SSH服务器

    1
    sudo /etc/init.d/ssh restart
  4. 查看IP地址

    1
    ip a

    打开SSH软件,填入步骤4中查看的IP地址,即可进行远程SSH访问。

Debian

Ubuntu

本人使用的Ubuntu 22.04系统会根据选择的语言及地区进行设置apt源,所以一般无需手动设置。

Armbian

config源文件:armbian-config.sources

1
2
3
4
5
Types: deb
URIs: https://github.armbian.com/configng
Suites: stable
Components: main
Signed-By: /usr/share/keyrings/armbian.gpg

apt源文件:/etc/apt/sources.list.d/armbian.list

修改为清华源:

1
2
3
4
5
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/armbian
Suites: bookworm
Components: main bookworm-utils bookworm-desktop
Signed-By: /usr/share/keyrings/armbian-archive-keyring.gpg

debian-security源文件:

修改为清华源:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/debian
Suites: bookworm bookworm-updates bookworm-backports
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
# Types: deb-src
# URIs: https://mirrors.tuna.tsinghua.edu.cn/debian
# Suites: bookworm bookworm-updates bookworm-backports
# Components: main contrib non-free non-free-firmware
# Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

# 以下安全更新软件源包含了官方源与镜像站配置,如有需要可自行修改注释切换
Types: deb
URIs: https://mirrors.tuna.tsinghua.edu.cn/debian-security
Suites: bookworm-security
Components: main contrib non-free non-free-firmware
Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

# Types: deb-src
# URIs: https://security.debian.org/debian-security
# Suites: bookworm-security
# Components: main contrib non-free non-free-firmware
# Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg

特别鸣谢


Linux基础配置
https://dongxunz.github.io/2025/07/08/Linux/Linux基础配置/
作者
dongxunz
发布于
2025年7月8日
许可协议