用于在远程服务器上创建用户的Linux脚本

我已经能够在远程服务器上创建用户,而以下命令没有问题。

ssh -i /home/centos/dummy.pem centos@host_ip  'sudo useradd -s /bin/bash -m testuser'

如果我尝试使用Shell脚本在远程服务器上创建用户,则会引发错误,并传递host_user,host_ip和new_user参数,例如 ./test.sh "host_user" "host_ip" "new_user"

#!/bin/bash

#Remote server login user
echo host_user=$1

#Remote server hostname
host_name=$2

#user name
user_name=$3

#user public key
#pub_key=$4

ssh $host_user@$host_name -i /home/centos/dummy.pem 'sudo useradd -s /bin/bash -m $user_name'

预期: 远程服务器上的新用户。

实际结果:

Usage: useradd [options] LOGIN
       useradd -D
       useradd -D [options]

Options:
  -b,--base-dir BASE_DIR       base directory for the home directory of the
                                new account
  -c,--comment COMMENT         GECOS field of the new account
  -d,--home-dir HOME_DIR       home directory

还尝试在脚本中使用“ -D”,但没有运气。

liuzuowei521 回答:用于在远程服务器上创建用户的Linux脚本

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3149910.html

大家都在问