交互方式修改密码

1. ssh 远程到主机;

2. 切换到root账号;

[一般都是切换到root进行密码修改,如果普通用户修改自己的密码,要输入原密码,然后新密码要满足复杂度才OK];

3. passwd username

使用passwd username 修改 username 的密码;
使用该命令会有提示,即进入了交互界面,输入密码即可。

使用脚本修改密码

很多时候我们可能需要远程执行服务器上的脚本来修改账号密码,此时就没有办法进行交互了。
此时可以使用如下两种方式修改密码:

方式1:

echo "password" | passwd testuser --stdin > /dev/null 2>&1

方式2:

echo testuser:password|chpasswd

注:

  1. 密码字符串的双引号,可有可无,见上面 方式1 和 方式2 的例子

  2. 如果密码中包含 $ 字符,需要使用反斜线进行转义,如:

echo testuser:password\$|chpasswd

Linux通过Shell脚本命令修改密码不需要交互的更多相关文章

  1. linux shell脚本批量修改密码,无需交互输入

    转至:https://blog.csdn.net/weixin_34409357/article/details/89833777?utm_medium=distribute.pc_relevant. ...

  2. linux 基础 shell脚本命令

    #########shell脚本命令#### 1.diff diff file file1 ####比较两个文件的不同 -c ####显示周围的行 -u ####按照一格式统一输出生成补丁 -r ## ...

  3. Linux执行shell脚本方式及区别&命令后台运行

    Linux执行shell脚本方式及区别&命令后台运行 http://blog.csdn.net/heqiyu34/article/details/19089951/

  4. 常用shell脚本命令

    常用shell脚本命令 1.显示包含文字aaa的下一行的内容: sed -n '/aaa/{n;p;}' filename 2.删除当前行与下一行的内容: sed -i '/aaa/{N;d;}' f ...

  5. 从windows到linux的shell脚本编码和格式问题

    从windows到linux的shell脚本编码和格式问题   从windows到Linux的shell脚本编码和格式问题 1.异常问题 :set ff=unix 启动脚本在启动时报错比如执行sh s ...

  6. linux 常用shell脚本语句

    最近老大让写一个shell脚本,每天从一个固定IP中取到相应文件,所以想写一个简单的shell脚本命令,供大家学习交流.先做一个简单的例子,先看效果吧, 代码如下: #!/bin/sh #定义一个变量 ...

  7. Linux简单Shell脚本监控MySQL、Apache Web和磁盘空间

    Linux简单Shell脚本监控MySQL.Apache Web和磁盘空间 1. 目的或任务 当MySQL数据库.Apache Web服务器停止运行时,重新启动运行,并发送邮件通知: 当服务器磁盘的空 ...

  8. Linux:从windows到linux的shell脚本编码和格式

    从windows到linux的shell脚本编码和格式问题 异常问题 :set ff=unix 启动脚本在启动时报错比如执行sh start.sh,时会报Command not found等等的错误, ...

  9. 详解Linux交互式shell脚本中创建对话框实例教程_linux服务器

    本教程我们通过实现来讲讲Linux交互式shell脚本中创建各种各样对话框,对话框在Linux中可以友好的提示操作者,感兴趣的朋友可以参考学习一下. 当你在终端环境下安装新的软件时,你可以经常看到信息 ...

随机推荐

  1. python生成html表格

    最近做一个小工具,需要将统计数据生成html表格.在网上搜罗一圈后发现用pandas生成表格非常好用.代码如下: import pandas as pd def convertToHtml(resul ...

  2. Oracle数据库中设置表字段为自动序列

    --创建序列 increment ; --创建触发器 create or replace trigger zonecode_trigger before insert on org_HospitalZ ...

  3. Spring返回json数据

    第一种形式:使用注解@ResponseBody @RequestMapping(value = "/admin/jq", method = RequestMethod.GET) @ ...

  4. element ui下拉框如何实现默认选择?

    <template> <el-select v-model="value4" clearable placeholder="请选择"> ...

  5. python mysql安装

    本文主要介绍不同系统mysql安装 mac安装mysql http://blog.csdn.net/pansanday/article/details/54915916   linux安装mysql ...

  6. leetcode-longest palindromic substring-by 1337c0d3r

    Given a string S, find the longest palindromic substring in S. Note:This is Part II of the article:  ...

  7. linux 下apche无法监听端口解决办法(Permission denied: make_sock: could not bind to address)

    想建立一个测试用的虚拟主机,遇到了这个问题:[root@localhost html]# service httpd startStarting httpd: httpd: Could not rel ...

  8. yii2.0 Activeform表单部分组件使用方法 [ 2.0 版本 ]

    文本框:textInput(); 密码框:passwordInput(); 单选框:radio(),radioList(); 复选框:checkbox(),checkboxList(); 下拉框:dr ...

  9. webpack学习(五)配置详解

    配置详解 //使用插件html-webpack-plugin打包合并html //使用插件extract-text-webpack-plugin打包独立的css //使用UglifyJsPlugin压 ...

  10. Django 玩转API

    现在,让我们进入Python的交互式shell,玩转这些Django提供给你的API. 使用如下命令来调用Python shell: $ python manage.py shell 我们使用上述命令 ...