惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
I
InfoQ
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
IT之家
IT之家
云风的 BLOG
云风的 BLOG
有赞技术团队
有赞技术团队
Martin Fowler
Martin Fowler
MyScale Blog
MyScale Blog
The GitHub Blog
The GitHub Blog
博客园_首页
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
G
Google Developers Blog
WordPress大学
WordPress大学
B
Blog
人人都是产品经理
人人都是产品经理
小众软件
小众软件
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
量子位
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
Last Week in AI
Last Week in AI
博客园 - 聂微东
Jina AI
Jina AI

运维开发绿皮书

OBS虚拟摄像头重命名 Ubuntu备份为LiveOS 使用Powershell卸载windows默认程序 Cisco路由器OSPF配置 汽车的分类和特点 Windows11跳过TPM2.0 HTTPS 双向认证与 USB 加密锁配置实战 SSL 证书工具 字数统计 BMI 计算 颜色转换 Hash 生成器 JSON 格式化 JWT 解码 房贷计算 时间戳转换 URL 编码 UUID 生成 牛马时钟 二维码批量生成器 CKS Simulator Kubernetes 1.25 FRP TOTP验证码生成器 direct-ssh-passthrough-nat 脚本使用说明 Python软件授权 Linux命令行百度网盘 为 Containerd 配置 Harbor 无证书镜像站 Docker一键部署Meta和MetacubexD面板 必应搜索屏蔽垃圾网站 VMware的ubuntu完整安装vm-tools支持粘贴板
Gitlab批量创建用户
Paper-Dragon · 2025-08-26 · via 运维开发绿皮书

Gitlab批量创建用户

一、获取Personal Access Tokens

1、使用有admin权限的账号登录GitLab;

2、单击右上角的头像,点击"Settings"进入设置页面;

3、点击左侧菜单Access Tokens,然后生成 Personal Access Tokens;

image-20250825154257249

4、将生成的personal access token记录下来,后面会用到。

二、准备脚本文件

创建userlist.txt文件,内容格式如下:

xxxxxxx@G1t2025 songxxxx@xxxxxxxxx.cn xxxx 宋xx
xxxxxxx@G1t2025 lixxxx@xxxxxxxxx.cn xxxx 李xx
xxxxxxx@G1t2025 longxxxx@xxxxxxxxx.cn xxxx 龙xx
xxxxxxx@G1t2025 lixxxx@xxxxxxxxx.cn xxxx 李xx
xxxxxxx@G1t2025 qixxxx@xxxxxxxxx.cn xxxx 祁xx
xxxxxxx@G1t2025 zengxxxx@xxxxxxxxx.cn xxxx 曾xx
xxxxxxx@G1t2025 yuxxxx@xxxxxxxxx.cn xxxx 余xx
xxxxxxx@G1t2025 lixxxx@xxxxxxxxx.cn xxxx 李xx
xxxxxxx@G1t2025  Shixxxx@xxxxxxxxx.cn  xxxx 师xx

对应字段分别是:密码 邮箱 用户名 别名,字段可以按需调整。

创建 gitlabAddUser.sh 文件,内容如下:

#!/bin/bash
 
# 用户信息文件
userinfo="userlist.txt"
# 读取文件
while read -r line
do
    # 去除行首尾空格
    l=`echo $line | awk '{gsub(/^\s+|\s+$/, "");print}'`
    echo $l
    # 按照空格分隔  字段顺序按需调整,但需与userinfo.txt文件一致
    password=`echo $l | awk '{print $1}'`
    email=`echo $l | awk '{print $2}'`
    username=`echo $l | awk '{print $3}'`
    name=`echo $l | awk '{print $4}'`
    # 发送post请求 token与url需更换为自己的
    curl -X POST -H "PRIVATE-TOKEN: token-tokenxxxxxABCDEF" "http://test.gitlab.com/api/v4/users" -H 'cache-control: no-cache' -H 'content-type: application/json' \
    -d '{ "email": "'"$email"'", "username": "'"$username"'", "password": "'"$password"'", "name": "'"$name"'", "skip_confirmation": "true" }'
    echo ""
done < $userinfo

其中PRIVATE-TOKEN需要改为第一步获取到的personal access token, API地址http://test.gitlab.com/api/v4/users需要改为自己的gitlab服务器地址,相应的api可查看gitlab的官方文档https://docs.gitlab.com/ce/api/

三、执行脚本命令

打开shell命令窗口,找到 gitlabAddUser.sh 文件,给此文件添加可执行权限,执行gitlabAddUser.sh。

chmod +x gitlabAddUser.sh
sh gitlabAddUser.sh