栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

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

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

通过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 
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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/860442.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号