通过ssh批量修改主机密码(无sudo权限)-go现学现卖五一版

疫情的五一注定没地方可去,干点啥呢。。。。。卷起来算了,把最近学的golang用用吧,于是把之前用python写的通过ssh批量修改主机密码的运维小工具用go重新写了一遍,虽然没用go的协程,用起来也算顺手了,能交叉编译、运行无依赖算是go的大强项吧。

当然,如果你有sudo权限或者root,那就直接用ansible就行了,可我就悲剧了,没有sudo权限,密码还3个月失效一次,密码还不能和前10次相同,主机还50+。。。。。。。。不用程序天理难容……^_^

下载:

GitHub - sjwhi8989/changepasswd: Modify the host password in batches through ssh interactively

使用方法:

1、新建配置文件host.cfg,把要修改的主机都写上,支持按照片段设置公共的ssh连接参数,也能在主机列表里单独指定该主机的ssh连接参数,参数说明:

ssh_port :ssh连接端口
ssh_user :ssh连接用户名
ssh_pass :ssh连接密码
ssh_pass_new :要修改为的新密码

# host.cfg
[testPC01:vars]
ssh_port=22
ssh_user=test
ssh_pass=pass01
ssh_pass_new=passnew01
#ssh_pass=passnew01
#ssh_pass_new=pass01

[testPC01]
h=192.168.100.1 ssh_port=22022  ssh_user=sjw  ssh_pass=pass03
h=192.168.100.2 ssh_pass=pass03

[testPC02]
h=192.168.100.3 ssh_port=22022  ssh_user=sjw  ssh_pass=pass03
h=192.168.100.4 ssh_port=22     ssh_user=sjw  ssh_pass=pass03

 2、比如要修改[testPC01]片段里的主机密码:

./changepasswd -s testPC01 -do changepasswd

3、也可以在修改前验证下配置文件里的密码是否正确:

./changepasswd -s testPC01

4、修改完密码后还可以用新密码登录看看是否能登录:

./changepasswd -s testPC01  -passnew

5、更多帮助信息用 -h 参数:

./changepasswd -h

v1.0 at 2022-05-03 created by <sjwwork@163.com>
Function: Modify the host password in batches through ssh interactively .
Options:
-c file
  	set configuration file (default "host.cfg")
-debug
  	print debug info
-do checklogin | changepasswd
  	checklogin | changepasswd (default "checklogin")
-h	this help
-passnew
  	using ssh_pass_new in configuration file to checklogin
-s string
  	using section in configuration file
-timeout uint
  	the ssh connection timeout (seconds)  (default 5)
-v	show version and exit

host.cfg Example

  [testPC01:vars]
  ssh_port=22
  ssh_user=test
  ssh_pass=pass01
  ssh_pass_new=passnew01
  #ssh_pass=passnew01
  #ssh_pass_new=pass01

  [testPC01]
  h=192.168.100.1 ssh_port=22022  ssh_user=sjw  ssh_pass=pass03
  h=192.168.100.2 ssh_pass=pass03

  [testPC02]
  h=192.168.100.3 ssh_port=22022  ssh_user=sjw  ssh_pass=pass03
  h=192.168.100.4 ssh_port=22     ssh_user=sjw  ssh_pass=pass03

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sjwbcb

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值