分类 Other-经验分享 下的文章

Ubuntu 20.04 中使用OpenVPN搭建VPN服务器


和其它的文章不同,以下是很简单的搭建方法
1、升级系统打上补丁可以使用以下命令行

sudo apt update
sudo apt upgrade -y

2、下载openvpn的安装脚本,使用脚本安装省去安装证书等过程。我们可以通过以下命令下载脚本并运行脚本

wget https://git.io/vpn -O openvpn-ubuntu-install.sh
chmod -v +x openvpn-ubuntu-install.sh
sudo ./openvpn-ubuntu-install.sh

在安装过程选择如下图:
主要选项是协议一般选择UDP,DNS可以任意选择,Client名称可以自己名字,运行完脚本最终会在 /root目录下生成一个 .ovpn文件,这个正是我们上网的凭证文件。同时vpn服务也会自动安装好了
3、我们可以通过以下命令来管理vpn服务

sudo systemctl status openvpn-server@server.service
sudo systemctl start openvpn-server@server.service
sudo systemctl stop openvpn-server@server.service
sudo systemctl restart openvpn-server@server.service

4、如果我们还要添加用户可以继续运行以下脚本

 sudo ./openvpn-ubuntu-install.sh

端口测试

nc -vuz 159.135.192.235 1194
// Connection to 159.135.192.235 1194 port [udp/openvpn] succeeded!

https://gist.github.com/ebta/301f286fa9056d67e61bfc7cedd4ad56
相关链接:
https://linuxconfig.org/basic-ubuntu-22-04-openvpn-client-server-connection-setup
https://kifarunix.com/install-and-setup-openvpn-server-on-ubuntu-22-04/
https://www.cyberciti.biz/faq/ubuntu-20-04-lts-set-up-openvpn-server-in-5-minutes/


jenkins 配置 ssh 访问GitHub


生成 SSH key(推荐 ed25519)

ssh-keygen -t ed25519 -C "jenkins@your-domain" -f /var/jenkins_home/.ssh/id_ed25519

生成后会有:

  • 私钥:/var/jenkins_home/.ssh/id_ed25519
  • 公钥:/var/jenkins_home/.ssh/id_ed25519.pub

把公钥加到 Git 仓库平台(以 GitHub 为例)

  1. 查看公钥内容:

    cat /var/jenkins_home/.ssh/id_ed25519.pub
  2. 打开 GitHub → 右上角头像 → Settings → SSH and GPG keys → New SSH key

  3. 把刚才复制的公钥粘贴进去,保存。
    GitLab / Gitea / 自建 Git 也类似:找到 SSH Keys 设置,加进去即可。

在 Jenkins 里添加 SSH 凭据(Credentials)

  1. 打开 Jenkins Web 页面。
  2. 左侧:Manage Jenkins → Credentials → (Global)
  3. 右侧:Add Credentials
  4. 选择:
    • KindSSH Username with private key(中文界面类似)
    • Username
      • GitHub / GitLab 通常填写:git
    • Private Key
      • Enter directly
      • /var/jenkins_home/.ssh/id_ed25519 里的内容复制进去
        (用 cat /var/jenkins_home/.ssh/id_ed25519 查看,然后复制)
    • ID / Description:随便填一个有意义的,比如:github-ssh-universe
  5. 保存。

配置 Job 使用 SSH 仓库 + 关联凭据

1. 确保仓库 URL 是 SSH 形式

例如 GitHub:

git@github.com:xxx/xxx.git

不是:

https://github.com/xxx/xxx.git

在 Pipeline(Jenkinsfile)里使用 SSH 凭据(可选)

如果你用的是声明式 Pipeline,可以这样写:

pipeline {
    agent any
    stages {
        stage('Checkout') {
            steps {
                git branch: 'main',
                    url: 'git@github.com:universe-web3/universe-deploy-ansible.git',
                    credentialsId: 'github-ssh-universe'
            }
        }
    }
}

注意

Jenkins 用 SSH 拉 github.com 时,要求严格校验证书(StrictHostKeyChecking=yes),但 known_hosts 里没有 github.com 的主机指纹,所以直接拒绝。

在 Jenkins Web 界面里调整 Git Host Key 策略

可以让 Jenkins 自己“自动信任”第一次连接的 host key(安全性稍差,但在你自己控制的环境里一般也可以接受)。

  1. 打开 Jenkins → 左侧 Manage Jenkins
  2. 找到 Configure Global Security
  3. 往下找到 Git Host Key Verification Configuration
  4. 选择其中一个策略:
    • Known hosts file Verification Strategy(默认,配合上面方案一)
    • 或者 Accept first connection(第一次自动接受 host key,以后照这个校验)

保存之后,再去构建你的 Job 试一次。