- 2013-09-29国务院近日印发了上海自由贸易试验区总体方案,自贸区...
- 2013-09-29移动医疗大潮袭来,看着是肉 咬下去是骨头。
- 2013-09-28安卓阵营集体遭360洗劫,华为三星步步高悉数中枪
- 2013-09-28小米MIUI团队声明称应用商店内全线下架360产品
- 2013-09-25阿里巴巴与云存储应用酷盘的收购谈判行已结束,阿里巴...
- 2013-09-25苹果称其全新Touch ID指纹扫描安全系统可以“十分安全...
- 2013-09-24上海自贸区不设防火墙 脸谱和推特等解禁
- 2013-09-24Fairfax Financial计划收购黑莓:每股9美元 总价47亿美...
- 2013-09-24消息称苏宁洽购PPTV进入尾声 金额约为4亿美元
- 2013-09-238月25日凌晨,中国.CN域名解析出现大规模解析故障,攻击...
CloudStack设置Linux重置密码功能
接着上文讲CloudStack下设置重置Linux系统密码。这里我们主要分别介绍CentOS和Ubuntu下如何设置。
CentOS
1、下载重置密码的脚本cloud-set-guest-password,脚本内容具体见文章下面的附件;
2、将文件上传到/etc/init.d;
3、检查文件格式:cat -v cloud-set-guest-password(如果发现有乱码,则运行dos2unix cloud-set-guest-password)
这一步很重要,很多重置密码失败都是因为编码的问题;
4、给文件设置运行权限:chmod +x /etc/init.d/cloud-set-guest-password;
5、加入启动项:chkconfig --add cloud-set-guest-password。
Ubuntu
1、下载重置密码的脚本cloud-set-guest-password,脚本内容具体见文章下面的附件;
2、将文件上传到/etc/init.d;
3、检查文件格式:cat -v cloud-set-guest-password(如果发现有乱码,则运行dos2unix cloud-set-guest-password)
这一步很重要,很多重置密码失败都是因为编码的问题;
4、加入启动项:sudo update-rc.d cloud-set-guest-password defaults 98;
5、设置sh指向:dpkg-reconfigure dash(会弹出框,选择否)。
附件:
CentOS下的cloud-set-guest-password脚本内容:
#!/bin/bash # # cloud-set-guest-assword Init file for Password Download Client # # chkconfig: 2345 98 02 # description: Init file for Password Download Client ### BEGIN INIT INFO # Provides: cloud-set-guest-password # Required-Start: $local_fs $network # Required-Stop: $local_fs $syslog # Should-Start: $syslog # Should-Stop: $network $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Init file for Password Download Client # Description: Init file for Password Download Client ### END INIT INFO # Source function library. . /etc/rc.d/init.d/functions # Modify this line to specify the user (default is root) user=root # Add your DHCP lease folders here DHCP_FOLDERS="/var/lib/dhclient/*" function cloud_set_guest_password() { password_received=0 file_count=0 error_count=0 for DHCP_FILE in $DHCP_FOLDERS; do if [ -f $DHCP_FILE ]; then file_count=$((file_count+1)) PASSWORD_SERVER_IP=$(grep dhcp-server-identifier $DHCP_FILE | tail -1 | awk '{print $NF}' | tr -d '\;') if [ -n $PASSWORD_SERVER_IP ]; then logger -t "cloud" "Found password server IP $PASSWORD_SERVER_IP in $DHCP_FILE" logger -t "cloud" "Sending request to password server at $PASSWORD_SERVER_IP" password=$(wget -q -t 3 -T 20 -O - --header "DomU_Request: send_my_password" $PASSWORD_SERVER_IP:8080) password=$(echo $password | tr -d '\r') if [ $? -eq 0 ]; then logger -t "cloud" "Got response from server at $PASSWORD_SERVER_IP" case $password in "") logger -t "cloud" "Password server at $PASSWORD_SERVER_IP did not have any password for the VM" continue ;; "bad_request") logger -t "cloud" "VM sent an invalid request to password server at $PASSWORD_SERVER_IP" error_count=$((error_count+1)) continue ;; "saved_password") logger -t "cloud" "VM has already saved a password from the password server at $PASSWORD_SERVER_IP" continue ;; *) logger -t "cloud" "VM got a valid password from server at $PASSWORD_SERVER_IP" password_received=1 break ;; esac else logger -t "cloud" "Failed to send request to password server at $PASSWORD_SERVER_IP" error_count=$((error_count+1)) fi else logger -t "cloud" "Could not find password server IP in $DHCP_FILE" error_count=$((error_count+1)) fi fi done if [ "$password_received" == "0" ]; then if [ "$error_count" == "$file_count" ]; then logger -t "cloud" "Failed to get password from any server" exit 1 else logger -t "cloud" "Did not need to change password." exit 0 fi fi logger -t "cloud" "Changing password ..." echo $password | passwd --stdin $user if [ $? -gt 0 ]; then logger -t "cloud" "Failed to change password for user $user" fi logger -t "cloud" "Successfully changed password for user $user" logger -t "cloud" "Sending acknowledgment to password server at $PASSWORD_SERVER_IP" wget -t 3 -T 20 -O - --header "DomU_Request: saved_password" $PASSWORD_SERVER_IP:8080 } # See how we were called. case "$1" in start) action $"Starting cloud-set-guest-password: " /bin/true cloud_set_guest_password RETVAL=$? ;; stop) action $"Shutting down cloud-set-guest-password: " /bin/true RETVAL=$? ;; restart) $0 stop $0 start ;; *) echo $"Usage: cloud-set-guest-sshey {start}" RETVAL=2 ;; esac exit $RETVAL
Ubuntu下的cloud-set-guest-password脚本内容:
#!/bin/bash # # Init file for Password Download Client # ### BEGIN INIT INFO # Provides: cloud-set-guest-password # Required-Start: $local_fs $syslog $network # Required-Stop: $local_fs $syslog $network # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Init file for Password Download Client ### END INIT INFO set -e . /lib/lsb/init-functions # Modify this line to specify the user (default is root) user=root # Add your DHCP lease folders here DHCP_FOLDERS="/var/lib/dhcp/* /var/lib/dhcp3/*" function cloud_set_guest_password() { password_received=0 file_count=0 error_count=0 for DHCP_FILE in $DHCP_FOLDERS; do if [ -f $DHCP_FILE ]; then file_count=$((file_count+1)) PASSWORD_SERVER_IP=$(grep dhcp-server-identifier $DHCP_FILE | tail -1 | awk '{print $NF}' | tr -d '\;') if [ -n "$PASSWORD_SERVER_IP" ]; then logger -t "cloud" "Found password server IP $PASSWORD_SERVER_IP in $DHCP_FILE" logger -t "cloud" "Sending request to password server at $PASSWORD_SERVER_IP" password=$(wget -q -t 3 -T 20 -O - --header "DomU_Request: send_my_password" $PASSWORD_SERVER_IP:8080) password=$(echo $password | tr -d '\r') if [ $? -eq 0 ]; then logger -t "cloud" "Got response from server at $PASSWORD_SERVER_IP" case $password in "") logger -t "cloud" "Password server at $PASSWORD_SERVER_IP did not have any password for the VM" continue ;; "bad_request") logger -t "cloud" "VM sent an invalid request to password server at $PASSWORD_SERVER_IP" error_count=$((error_count+1)) continue ;; "saved_password") logger -t "cloud" "VM has already saved a password from the password server at $PASSWORD_SERVER_IP" continue ;; *) logger -t "cloud" "VM got a valid password from server at $PASSWORD_SERVER_IP" password_received=1 break ;; esac else logger -t "cloud" "Failed to send request to password server at $PASSWORD_SERVER_IP" error_count=$((error_count+1)) fi else logger -t "cloud" "Could not find password server IP in $DHCP_FILE" error_count=$((error_count+1)) fi fi done if [ "$password_received" == "0" ]; then if [ "$error_count" == "$file_count" ]; then logger -t "cloud" "Failed to get password from any server" exit 1 else logger -t "cloud" "Did not need to change password." exit 0 fi fi logger -t "cloud" "Changing password ..." if [ -x /usr/sbin/chpasswd ]; then echo "${user}:${password}" | chpasswd else echo $password | passwd --stdin $user if [ $? -gt 0 ]; then logger -t "cloud" "Failed to change password for user $user" exit 1 else logger -t "cloud" "Successfully changed password for user $user" fi fi logger -t "cloud" "Sending acknowledgment to password server at $PASSWORD_SERVER_IP" wget -t 3 -T 20 -O - --header "DomU_Request: saved_password" $PASSWORD_SERVER_IP:8080 } case "$1" in start) log_action_msg "Starting cloud" "cloud-set-guest-password" sleep 10 cloud_set_guest_password if [ $? -eq 0 ]; then log_end_msg 0 else log_end_msg 1 fi ;; stop) log_action_msg "Stopping cloud" "cloud-set-guest-password" log_end_msg 0 ;; *) log_action_msg "Usage: /etc/init.d/cloud-set-guest-password {start}" exit 1 ;; esac exit 0
注:本站部分信息可能源于互联网分享,如有侵权,请告知,我们将及时删除!
- 用户评论
- 相关文章
-
最新评论
-
1
使用IIS+Resin来配置J...
本文介绍使用IIS+Resin来配置JSP的运行环境... -
2
MYSQL的主要参数设置(...
MYSQL的主要参数设置(优化) -
3
Linux服务器安全小技巧...
Linux 服务器安全小技巧 -
4
批量修改计算机名
批量修改计算机名 -
5
Linux下安装apache
Linux下安装apache -
6
Windows日志NTFS错误
Windows日志NTFS错误