通过ssh批量修改主机密码

通过ssh批量修改主机密码,第1张

疫情的五一注定没地方可去,干点啥呢。。。。。卷起来算了,把最近学的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 
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

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/867868.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-12
下一篇2022-05-12

发表评论

登录后才能评论

评论列表(0条)

    保存