【发布时间】:2016-02-02 07:38:04
【问题描述】:
我正在尝试将用户添加到我的 LAN pc(ubuntu 14.04) 但失败了。 比如说:
mypc : 192.168.0.11 serverpc : 192.168.0.100
我可以使用 shell 脚本将用户创建到“mypc”中。但是当我尝试连接并将用户添加到“serverpc”时:它返回“添加用户失败!”。我正在使用 PHP:
这是我的方法:
public function test_ldap(){
$username = escapeshellarg('different');
$password = escapeshellarg('different');
#$udomain = 'edutechsolutionsbd.com';
$u_domain = '192.168.0.100';
$u_user = 'etsb';
$output = exec("sudo shell_script/add_user.sh $username $password $u_domain $u_user 2>&1");
#$output = shell_exec("/usr/bin/php -v");
print_r($output);
exit;
}
shell脚本::
#!/bin/bash
# Script to add a user to Linux system
# -------------------------------------------------------------------------
# Copyright (c) 2007 nixCraft project <http://bash.cyberciti.biz/>
# This script is licensed under GNU GPL version 2.0 or above
# Comment/suggestion: <vivek at nixCraft DOT com>
# -------------------------------------------------------------------------
# See url for more info:
# http://www.cyberciti.biz/tips/howto-write-shell-script-to-add-user.html
# -------------------------------------------------------------------------
if [ $(id -u) -eq 0 ]; then
username=$1
password=$2
u_domain=$3
u_user=$4
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
#useradd -m -p $pass $username
sudo ssh $u_user@$u_domain "useradd -m -p $pass $username"
[ $? -eq 0 ] && echo "User is Created Successfully!" || echo "Failed to add a user!"
fi
else
echo "Only root may add a user to the system"
exit 2
fi
我的问题:如何在 ubuntu 中将用户创建到我的另一台电脑中?提前致谢。
【问题讨论】: