Ubuntu相关操作
常规操作
换源
使用清华的源https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
先备份源文件
sudo mv /etc/apt/sources.list /etc/apt/sources.list.bk
写入新的源
sudo vim /etc/apt/sources.list
仅包含 32/64 位 x86 架构处理器的软件包
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
在 ARM(arm64, armhf)、PowerPC(ppc64el)、RISC-V(riscv64) 和 S390x 等架构的设备上(对应官方源为 ports.ubuntu.com)使用:
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multivers
更新源
sudo apt-get update
open too many files
打开的文件描述符超限了
vim /etc/security/limits.conf
* soft nproc 1000000
* hard nproc 1000000
* soft nofile 1000000
* hard nofile 1000000
重新登录即可
查看所允许最大文件数
[root@localhost ~]# cat /proc/sys/fs/file-max
2000000
ssh连接Permission denied (publickey)
可能是Linux上ssh服务没有开密码登录
sudo vim /etc/ssh/sshd_config
找到PasswordAuthentication
,将no
改为yes
PasswordAuthentication yes
找到PubkeyAuthentication
,将yse
改为no
然后重启服务
sudo systemctl restart sshd
创建一个新用户
创建一个新用户
sudo adduser <username>
将用户添加到sudo组中,以便拥有管理员权限
sudo usermod -aG sudo <username>
修改目录所有者
递归修改目录及其目录中的文件的所有者
sudo chown -R <用户名>:<用户组> 目标目录
为应用创建守护进程
编写一个服务文件,通常放在 /etc/systemd/system/
目录下,命名规则为 your-service-name.service
。可以使用文本编辑器打开并编辑该文件。
sudo vi /etc/systemd/system/your-service-name.service
在服务文件中定义服务的描述信息、启动命令、停止命令、依赖关系等,以下是一个示例:
[Unit]
Description=<Your Service Name>
[Service]
KillMode=process
LimitNOFILE=102400
Environment=BINPATH=<binary path>
WorkingDirectory=<binary path>
Type=forking
ExecStart=/usr/bin/bash -c "${BINPATH}/run.sh start"
ExecStop=/usr/bin/bash -c "${BINPATH}/run.sh stop"
ExecReload=/usr/bin/bash -c "${BINPATH}/run.sh restart"
Restart=on-failure
[Install]
WantedBy=multi-user.target
说明:
[Unit]
段包含服务的描述信息和依赖关系。[Service]
段包含服务的启动命令和重启策略。[Install]
段包含服务的安装信息。
启用服务并设置为开机自启动。
sudo systemctl enable your-service-name.service
启动服务。
sudo systemctl start your-service-name.service
检查服务状态。
sudo systemctl status your-service-name.service
如果服务的状态显示为 active (running)
,则说明服务已经成功启动,并且已经设置为开机自启动。如果服务的状态显示为 inactive (dead)
,则说明服务启动失败,请检查服务文件中的配置是否正确。
禁用守护进程
sudo systemctl disable your-service-name.service
配置root用户
# 为root用户设置密码
sudo passwd root
#登录到root用户
su root
# 设置root用户可ssh登录
sudo vi /etc/ssh/sshd_config
#打开
LoginGraceTime 2m
PermitRootLogin yes
StrictModes yes
#重启ssh
sudo service ssh restart
设置root用户登录图形桌面
1)在终端中输入命令sudo vim /etc/pam.d/gdm-autologin
(前提是系统中安装有vim编辑器,安装命令是sudo apt-get install vim,也可以使用vi编辑器或nano编辑器)
2)注释'auth requied pam_succeed_if.so user != root quiet success'这一行,保存退出
3)在终端输入命令sudo vim /etc/pam.d/gdm-password
4)注释'auth requied pam_succeed_if.so user != root quiet success'这一行,保存退出
5)在终端输入命令sudo vi /root/.profile
6)在'mesg n 2> /dev/null || true'这一行前添加'tty -s && ',改为'tty -s && mesg n 2> /dev/null || true'
7)重启计算机,此时可以用ROOT用户登录,也可以使用原来安装时自己创建的普通用户登录,但是选择了普通用户后的用户选择列表并没有root用户,需要点击未列出手动输入root和密码来登录
安装make和Gcc
安装make
$ sudo apt install make
$ make --version
GNU Make 4.3
Built for aarch64-unknown-linux-gnu
Copyright (C) 1988-2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
安装gcc
$ sudo apt install build-essential
$ gcc --version
gcc (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Git
生成公钥
# 一路回车
ssh-keygen -t rsa -C "your email"
设置global参数
git config --global user.name "your user name"
git config --global user.email "your email"
# 查看所有配置
git config --global --list
代码拉取报错
仓库配置了ssh公钥,拉取代码报错:Their offer: ssh-rsa fatal: Could not read from remote repository.
vim ~/.ssh/config
Host *
HostkeyAlgorithms +ssh-rsa
PubkeyAcceptedKeyTypes +ssh-rsa
shell
查看所有shell
cat /etc/shells
查看当前sell
echo $SHELL
zsh安装
安装zsh
sudo apt install zsh
将默认的shell改为zsh
# 使用zsh
zsh
将zsh设置成默认shell
chsh -s /usr/bin/zsh
安装oh-my-zsh
前提已经安装了gt
# github安装
wget --no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
# giteea安装
sh -c "$(curl -fsSL https://gitee.com/shmhlsy/oh-my-zsh-install.sh/raw/master/install.sh)"
配置zsh
vim ~/.zshrc
#防止中文乱码
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
# 默认的路径
ZSH="~/.oh-my-zsh"
# 设置字体模式以及配置命令行的主题
#ZSH_THEME="robbyrussell" #默认主题
# 主题:https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="gallois" # 目前使用主题
GO安装
这里是之前在一台arm64的ubuntu安装的步骤,ubuntu amd64的操作方式是一样的
下载
wget https://golang.google.cn/dl/go1.17.13.linux-arm64.tar.gz
解压
tar -zxvf go1.17.13.linux-arm64.tar.gz -C ~/opt/programming/Go
创建目录
mkdir ~/opt/programming/Go/go_workspace
mkdir ~/opt/programming/Go/GOCACHE
touch ~/opt/programming/Go/ENV
$ ll ~/opt/programming/Go
total 12K
-rw-rw-r-- 1 ubuntu ubuntu 0 Mar 12 17:46 ENV
drwxr-xr-x 1 ubuntu ubuntu 608 Jul 30 2022 go
drwxrwxr-x 1 ubuntu ubuntu 64 Mar 12 17:46 GOCACHE
drwxrwxr-x 1 ubuntu ubuntu 64 Mar 12 17:46 go_workspace
配置环境变量
vim ~/.zshrc
export OPT_DIR=$HOME/opt
# Go
export GO_HOME=$OPT_DIR/programming/Go
export GOROOT=$GO_HOME/go
export GOPATH=$GO_HOME/go_workspace
export GOENV=$$GO_HOME/ENV
export GOCACHE=$GO_HOME/GOCACHE
export PATH=$PATH:$GOROOT/bin:$GOPATH
export GO111MODULE=on
export GOPROXY=https://goproxy.io,direct
source ~/.zshrc
查看版本
$ go version
go version go1.17.13 linux/arm64