用戶調整
# 創建新用戶
sudo adduser newusername
# 設置新用戶的密碼
sudo passwd newusername
# 將新用戶添加到 sudo 組
sudo usermod -aG sudo newusername
# 修改ssh訪問權限
sudo nano /etc/ssh/sshd_config
# 將新用戶加入,此時root將無法訪問
AllowUsers newusername
# 重啟服務
sudo service ssh restart
# 之后登錄
ssh newusername@x.x.x.x
# 登錄進入之后,切回root使用
su -
docker安裝
# 更新
apt -update
# 安裝docker
apt install docker.io
# 配置源
sudo nano /etc/docker/daemon.json
{"registry-mirrors": ["https://docker.m.daocloud.io","https://docker.imgdb.de","https://docker-0.unsee.tech","https://docker.hlmirror.com","https://docker.1ms.run","https://func.ink","https://lispy.org","https://docker.xiaogenban1993.com"]
}
# 拉取image
docker pull xx/xx
# 通過dockerfile制作image
docker build -t my-python-app .
# 通過docker-compose.yml制作鏡像
docker-compose up --build
# 以后臺模式運行容器
docker-compose up -d
# 查詢鏡像
docker images
# 刪除鏡像
docker rmi my-python-app
# 創建容器
docker run -d -p 8000:5000 --name my-python-app-container my-python-app
# 查詢容器
docker ps -a
# 關閉容器
docker stop xxxx
# 刪除容器
docker rm xxxx
# 查看容器log
docker logs xxxx
PostgreSQL
# 安裝
sudo apt install postgresql postgresql-contrib
# 查看版本號
sudo -u postgres psql -c "SELECT version();"
# 切用戶
sudo -i -u postgres
# 命令行
psql
# 修改用戶密碼
ALTER USER postgres PASSWORD 'your_password';
# 退出命令行
\q
# 配置遠程可訪問1
sudo nano /etc/postgresql/16/main/pg_hba.conf
host all all 0.0.0.0/0 md5
# 配置已遠程可訪問2
sudo nano /etc/postgresql/16/main/postgresql.conf
listen_addresses = '*'
# 重啟
sudo systemctl restart postgresql
# 查看端口
sudo lsof -i -P -n | grep postgres
其他
curl http://localhost:8000
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Index Page</title><link rel="stylesheet" href="/static/css/style.css">
</head>
<body><h1>Welcome to the Index Page</h1><script src="/static/js/script.js"></script>
</body>nc -zv xx.xx.xx.xx 8000
Connection to xx.xx.xx.xx port 8000 [tcp/irdmi] succeeded!# 遠程拷貝到本地
scp chenph@xx.xx.xx.xx:/home/chenph/HelloProj.tar.gz /Users/chenpenghao/Downloads# 本地到遠程
scp /path/to/local/file user@remote_server_ip:/path/to/remote/destination# 壓縮文件
tar -czvf HelloProj.tar.gz /home/proj/HelloProj# 移動文件
mv /path/to/source/file.txt /path/to/destination/# 重命名文件
mv old_file.txt new_file.txt# 拷貝單個文件
cp file.txt backup_file.txt# 拷貝多個文件
cp file1.txt file2.txt /path/to/destination/# 拷貝文件夾
cp -r folder/ /path/to/destination/# 刪除單個文件
rm file.txt# 刪除多個文件
rm file1.txt file2.txt# 刪除文件夾及其內容
rm -r folder/