Skip to content

debian配置

这里以debain12为例子,debain默认的vi对于输入情况可能存在问题,最好使用nano的情况,如果确定能够更新安装包了,考虑下载vim命令替代vi

一、修改ssh安全登陆

  1. 打开配置文件

    nano /etc/ssh/sshd_config
  2. 修改配置文件

打开下面四个参数的注释,或者直接复制这四个参数进去

LoginGraceTime 2m          #登陆时间
PermitRootLogin yes        #允许root登录
StrictModes yes            #严格模式
PasswordAuthentication yes
UseDNS no
  1. 重启服务

    systemctl restart ssh && systemctl restart sshd

二、修改源

清华源

tee /etc/apt/sources.list << EOF
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free

deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
# deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bullseye-security main contrib non-free
EOF

阿里源(推荐使用)

tee /etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/debian/ bookworm main contrib non-free-firmware non-free
deb-src http://mirrors.aliyun.com/debian/ bookworm main contrib non-free-firmware non-free

deb http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free-firmware non-free
deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main contrib non-free-firmware non-free

deb http://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free-firmware non-free
deb-src http://mirrors.aliyun.com/debian/ bookworm-backports main contrib non-free-firmware non-free

deb http://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free-firmware non-free
deb-src http://mirrors.aliyun.com/debian-security/ bookworm-security main contrib non-free-firmware non-free
EOF

替换源以后安装vim

apt update && apt upgrade && apt install -y vim

如果有缓存更新的问题,删除包再重新更新。

#删除缓存包
rm -rf /var/lib/apt/lists/*
#如果还有问题,删除源的文件
rm /etc/apt/sources.list && apt update

八、修改ip地址

注意自己网卡的名称。通过ip addr命令可以查看,或者查看配置文件/etc/network/interfaces,比如我的网卡为:ens18。复制相关的配置下去

image-20231213160730479

  1. 打开配置文件

    nano /etc/network/interfaces
  2. 编辑配置文件,并保存

    auto ens18
    iface ens18 inet static
        address 192.168.1.11
        netmask 255.255.255.0
        gateway 192.168.1.1
        dns-nameservers 8.8.8.8
  3. 重启网络

    systemctl restart networking

九、网络优化配置

  1. 修改网络配置

    tee /etc/sysctl.conf << EOF
    net.core.somaxconn= 10240
    vm.swappiness = 0
    kernel.sysrq = 1
    
    net.ipv4.neigh.default.gc_stale_time = 120
    
    # see details in https://help.aliyun.com/knowledge_detail/39428.html
    net.ipv4.conf.all.src_valid_mark = 1
    net.ipv4.ip_forward = 1
    net.ipv4.conf.all.rp_filter = 0
    net.ipv4.conf.default.rp_filter = 0
    net.ipv4.conf.default.arp_announce = 2
    net.ipv4.conf.lo.arp_announce = 2
    net.ipv4.conf.all.arp_announce = 2
    
    # see details in https://help.aliyun.com/knowledge_detail/41334.html
    net.ipv4.tcp_max_tw_buckets = 5000
    net.ipv4.tcp_syncookies = 1
    net.ipv4.tcp_max_syn_backlog = 8192
    net.ipv4.tcp_synack_retries = 2
    net.ipv4.tcp_slow_start_after_idle = 0
    EOF
  2. 执行生效动作

    sysctl -p

十、VIM复制粘贴

#这里要注意vim82这个文件目录,在不同的debain系统是不一样的,比如debian12为90
vim /usr/share/vim/vim82/defaults.vim

执行脚本,修改将 set mouse=a 改为:set mouse-=a

sed -i 's/set mouse=a/set mouse-=a/' /usr/share/vim/vim82/defaults.vim

debian12修改后的结果如下:

if has('mouse')
  if &term =~ 'xterm'
    set mouse-=a
  else
    set mouse=nvi
  endif
endif

十一、配置优化

11.1 文件显示

输入vi ~/.bashrc打开以下注释的内容,然后source ~/.bashrc让其生效

# You may uncomment the following lines if you want `ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval "$(dircolors)"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'

12.1 中文乱码

执行以下

echo -e "set encoding=utf-8\nset fileencodings=utf-8,gbk,gb2312" >> ~/.vimrc

十三、更新软件

#更新软件
apt update -y
#更新已安装的软件包
apt upgrade -y