我知道默认命令如下所示:
sudo mount -t cifs -o username=YOUR_USERNAME,password=YOUR_PASSWORD,uid=YOUR_UBUNTU_USERNAME //networkNameOfRemoteComputer/path/to/my/folder /path/to/mounting/dir
但是,我想安装一个samba共享文件夹,而不用硬编码我的密码。如果密码可见,我认为这会带来很高的安全风险。有人有主意吗?
(在此问题的上一版本中,我还要求安装不具有sudo权限,但似乎这是不可能的:()
请改用该mount.cifs
命令,因为它允许指定凭据文件或在未提供密码的情况下提示输入密码。
安装
首先,通过发出以下命令检查是否已安装所需的软件包:
sudo apt-get install cifs-utils
方法1-使用凭证文件
根据手册http://manpages.ubuntu.com/manpages/raring/man8/mount.cifs.8.html:
OPTIONS
[...]
凭证= filename指定包含用户名和/或口令和任选的工作组的名称的文件。该文件的格式为:用户名=值
密码=
值域=值
用法:
mount.cifs //<hostname_or_ip>/<cifs_share> <local_mountpoint> -o user=<user_to_connect_as>,rw,credentials=<path_to_the_credentials_file>
例子:
sudo mount.cifs //domain.com/share /mnt/domain_com -o user=admin,rw,credentials=/root/.credentials
重要的是要注意,“ name_of_the_user_to_connnect_as”也可以包含域或工作组:
user=workgroup/user
user=domain/user
(根据您的环境,您将需要更多或更少的选择)
关于安全性,将凭据文件存储在/ root目录中就足够了,但是如果要将其存储在其他位置,只需
sudo chown root <file>
方法2-提示密码
如果如上所述,您根本不希望密码可见,那么只需在mount.cifs
命令中不提供“ password”选项。
从位于http://manpages.ubuntu.com/manpages/hardy/man8/mount.cifs.8.html的手册页中
密码= arg
specifies the CIFS password. If this option is not given then the environment variable PASSWD is used. If the password is not specified directly or indirectly via an argument to mount mount.cifs will prompt for a password, unless the guest option is specified. Note that a password which contains the delimiter character (i.e. a comma ’,’) will fail to be parsed correctly on the command line. However, the same password defined in the PASSWD environment variable or via a credentials file (see below) or entered at the password prompt will be read correctly.
因此,以下命令应提示输入密码:
mount.cifs //<hostname_or_ip>/<cifs_share> <local_mountpoint> -o user=<user_to_connect_as>,rw
经过测试并按预期工作:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句