本文描述下debian11的初始化工作。
首先,我们使用普通用户登录到debian,然后使用su -
命令来切到root用户。注意: 一定要是su -
,而不是su
$ su -
设置IP地址
使用root登录后,修改/etc/network/interfaces
文件:
# The primary network interface
# 注释掉这行,并记录这个类似于 ens192 的关键字
# allow-hotplug ens192
# 注释点这行同时
#iface ens192 inet dhcp
# 加入以下行,注意ens192是我们从上面复制下来的,不同的电脑不一样
auto ens192
iface ens192 inet static
# 以下请根据自己的实际情况设置
address 192.168.1.17
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 192.168.1.1
编辑后退出,然后执行:systemctl restart networking.service
使配置生效.
安装sudo
默认debian11并没有安装sudo,安装过程如下:
更新源
如果操作系统是以CD方式安装的,那么CD会默认成为软件源(这在离线的网络环境中是必要的),而当前我们的服务器有网络环境,同时安装完操作系统后,CD已经弹出,所以此时需要取消掉软件源:
$ nano /etc/apt/sources.list
# 注释掉以cd rom开始的源
# deb cdrom:[Debian GNU/Linux 11.4.0 _Bullseye_ - Official amd64 DVD Binary-1 2>
# deb cdrom:[Debian GNU/Linux 11.4.0 _Bullseye_ - Official amd64 DVD Binary-1 2>
然后添加一些国内的官方源的中的华为镜像,最终文件如下:
# deb cdrom:[Debian GNU/Linux 11.4.0 _Bullseye_ - Official amd64 DVD Binary-1 20
220709-10:33]/ bullseye contrib main
# deb cdrom:[Debian GNU/Linux 11.4.0 _Bullseye_ - Official amd64 DVD Binary-1 20
220709-10:33]/ bullseye contrib main
# huawei
deb https://mirrors.huaweicloud.com/debian/ bullseye main contrib non-free
deb-src https://mirrors.huaweicloud.com/debian/ bullseye main contrib non-free
deb https://mirrors.huaweicloud.com/debian/ bullseye-updates main contrib non-free
deb-src https://mirrors.huaweicloud.com/debian/ bullseye-updates main contrib non-free
deb https://mirrors.huaweicloud.com/debian/ bullseye-backports main contrib non-free
deb-src https://mirrors.huaweicloud.com/debian/ bullseye-backports main contrib non-free
deb https://mirrors.huaweicloud.com/debian-security bullseye-security main contrib non-free
deb-src https://mirrors.huaweicloud.com/debian-security bullseye-security main contrib non-free
#deb http://security.debian.org/debian-security bullseye-security main contrib
#deb-src http://security.debian.org/debian-security bullseye-security main contr
ib
# bullseye-updates, to get updates before a point release is made;
# see https://www.debian.org/doc/manuals/debian-reference/ch02.en.html#_updates_
and_backports
# A network mirror was not selected during install. The following entries
# are provided as examples, but you should amend them as appropriate
# for your mirror of choice.
#
# deb http://deb.debian.org/debian/ bullseye-updates main contrib
# deb-src http://deb.debian.org/debian/ bullseye-updates main contrib
除此以外,你还可以将上述镜像中的mirrors.huaweicloud.com
替换为以下地址的任意关键字:
更新源
$ apt update
安装sudo
debian11默认未安装sodu,执行:apt install sudo
进行安装.
加入sudoers
$ usermod -aG sudo yourusername
然后,我们注销当前的shell,再重新登录一个。此时,便可以使用sudo命令了。
为root添加公钥
服务器添加允许root密码登录:
$ vi /etc/ssh/sshd_config
$ systemctl restart sshd
编辑内容如下:
PermitRootLogin yes
本地终端:
$ ssh-copy-id -i /path/of/public/key.pub -p portNumber username@service.name
服务器删除允许密码登录.
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。