samba
共有ディレクトリを設定するには、シェルスクリプトを使用してパスワードを設定したいと思います。私は次のスクリプトを書いたtest.sh
。
#!/bin/bash
pass=123456
(echo "$pass"; echo "$pass") | smbpasswd -s -a $(whoami)
これにより、次のものが印刷されます。
When run by root:
smbpasswd [options] [username]
otherwise:
smbpasswd [options]
options:
-L local mode (must be first option)
-h print this usage message
-s use stdin for password prompt
-c smb.conf file Use the given path to the smb.conf file
-D LEVEL debug level
-r MACHINE remote machine
-U USER remote username
extra options when run by root or in local mode:
-a add user
-d disable user
-e enable user
-i interdomain trust account
-m machine trust account
-n set no password
-W use stdin ldap admin password
-w PASSWORD ldap admin password
-x delete user
-R ORDER name resolve order
指摘したように、rootとして実行するのではなく、rootとして実行するとsudo ./test.sh
正常に動作します。しかし、問題は、私がログインしたユーザーであるものをroot
代わりに追加することです。noobuser
このようにしてどのようにnoobuser
追加できますか(ここで何か抜けたような感じがします)?
ベストアンサー1
テスト.sh:
#!/bin/bash
pass=123456
if [ -z "$SUDO_USER" ]; then
echo "This script is only allowed to run from sudo";
exit -1;
fi
(echo "$pass"; echo "$pass") | smbpasswd -s -a "$SUDO_USER"
移動する:
sudo ./test.sh