---
title: "linux shell - 远端修改非root密码"
author: "飞奔的熊猫"
date: "2015-01-09T20:40:52Z"
tags: []
categories: ["操作系统"]
slug: "linux-shell-root"
draft: false
lastmod: "2015-01-09T20:40:52Z"
id: 2174535
url: "https://runpanda.iteye.com/blog/2174535"
---

【基本介绍】
通过远端修改普通用户密码，而passwd --stdin , chpasswd都不许要root权限。

【方法介绍】
在要修改密码的机器上准备一个脚本

```linux
[root@bogon ~]# cat test.sh 
passwd <<EOF
$1
$2
$2
EOF
```


然后在远端调用脚本

```linux
[root@bogon ~]# ssh test@192.168.243.169 "/bin/bash /home/test/test.sh oldpass newpass"   
```



【其他方法】 - 有root权限

```linux
echo <newpasswd> | passwd --stdin <username>

echo <username>:<passwd> | chpasswd 
```


【参考引用】
<http://stackoverflow.com/questions/8236699/script-to-change-password-on-linux-servers-over-ssh>
<http://blog.chinaunix.net/uid-13670333-id-3187159.html>