mcE*_*nge 4 mount samba networking
我知道默认命令如下所示:
sudo mount -t cifs -o username=YOUR_USERNAME,password=YOUR_PASSWORD,uid=YOUR_UBUNTU_USERNAME //networkNameOfRemoteComputer/path/to/my/folder /path/to/mounting/dir
Run Code Online (Sandbox Code Playgroud)
但是我想挂载一个 samba 共享文件夹而无需硬编码我的密码。如果密码可见,我认为这是一个很高的安全风险。有没有人有想法?
(在此问题的先前版本中,我还要求在没有 sudo 权限的情况下进行安装,但这似乎是不可能的:()
请改用该mount.cifs命令,因为它允许指定凭据文件或在未提供密码时提示输入密码。
安装
首先,通过发出以下命令检查您是否安装了所需的软件包:
sudo apt-get install cifs-utils
Run Code Online (Sandbox Code Playgroud)
方法 1 - 使用凭证文件
根据手册http://manpages.ubuntu.com/manpages/raring/man8/mount.cifs.8.html:
OPTIONS
[...]
credentials=filename 指定包含用户名和/或密码以及可选的工作组名称的文件。文件格式为:用户名=值
密码=
值域=值
用法:
mount.cifs //<hostname_or_ip>/<cifs_share> <local_mountpoint> -o user=<user_to_connect_as>,rw,credentials=<path_to_the_credentials_file>
Run Code Online (Sandbox Code Playgroud)
例子:
sudo mount.cifs //domain.com/share /mnt/domain_com -o user=admin,rw,credentials=/root/.credentials
Run Code Online (Sandbox Code Playgroud)
请务必注意,“name_of_the_user_to_connnect_as”还可以包含域或工作组:
user=workgroup/user
user=domain/user
Run Code Online (Sandbox Code Playgroud)
(根据您的环境,您将需要更多或更少的选择)
关于安全性,把凭证文件存放在/root目录下应该就够了,但是如果你想把它存放在别处,就
sudo chown root <file>方法 2 - 密码提示
如果如上所述,您根本不希望您的密码可见,那么请不要在您的mount.cifs命令中提供“密码”选项。
来自http://manpages.ubuntu.com/manpages/hardy/man8/mount.cifs.8.html的联机帮助页
密码=参数
Run Code Online (Sandbox Code Playgroud)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
Run Code Online (Sandbox Code Playgroud)
经测试并按预期工作:
| 归档时间: |
|
| 查看次数: |
17871 次 |
| 最近记录: |