重置gitlab密码

1.进入控制台:

[root@hostname ~]# gitlab-rails console production
或者:
[root@hostname ~]# gitlab-rails console

2.定位到需要修改的用户

方法一:

通过用户名查找(推荐):

irb(main):001:0> user=User.where(username:'root').first

另一种写法(只能定位到普通用户,很容易出错造成找不到用户,返回 => nil,没有此用户的结果):

irb(main):002:0> User.where(name:'doudou').first

方法二:

通过id查找(一般修改root使用,因为root id=1):

irb(main):003:0> user=User.where(id:1).first

=> #<User id:1 @root>

方法三:

通过邮箱查找:

irb(main):004:0> user=User.find_by(email:'123@qq.com')

=> #<User id:92 @doudou>

3.重置密码:

一般数字密码就不用加引号:

irb(main):005:0>user.password=12345678

=> 12345678
有字符的密码一定要有引号(等号两边有空格):

irb(main):006:0>user.password = 'root@123'

=> “root@123”

4.确认新密码(可以省略):

irb(main):007:0>user.password_confirmation = 'root@123'

=> “root@123”

5.保存新密码:

irb(main):022:0>user.save!

Enqueued ActionMailer::DeliveryJob (Job ID: 04e11d87-7fc0-47a5-a792-aff11918335d) to Sidekiq(mailers) with arguments: “DeviseMailer”, “password_change”, “deliver_now”, #<GlobalID:0x00007fe595b63078 @uri=#<URI::GID gid://gitlab/User/10>>
=> true

最后是true就保存可以了!!!

irb(main):023:0>exit

扩展:

用脚本实现非交互式重置密码:
1.脚本需要使用到expect和spawn,yum安装一些包:
[root@hostname~]# yum install -y tcl tclx tcl-devel expect
[root@gmc-repository test]# vim gitlab.sh

#!/bin/sh
# \
exec expect -f "$0" "$@"
if { $argc != 2 } {
    puts "Usage: $argv0 <username> <passwd>"
    exit 1
}
set password [lindex $argv 1]
set name [lindex $argv 0]
spawn gitlab-rails console production
sleep 180
expect "irb(main)"
send "user=User.where(name:'$name').first\r"
expect "irb(main)"
send "user.password=$password\r"
expect "irb(main)"
send "user.password_confirmation=$password\r"
expect "irb(main)"
send "user.save!\r"
sleep 3
expect "irb(main)"
send "quit\r"
expect eof

执行脚本需要先加权限:
chmod u+x gitlab.sh
执行脚本需要两个参数:username passwd:

[root@hoastname test]# ./gitlab.sh weiliyan 12345678
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值