access windows share with smbclient and mount with cifs

本文介绍如何在Windows服务器上设置文件共享,并通过Ubuntu客户端使用SMB协议访问这些共享文件夹。具体步骤包括创建共享文件夹、设置访问权限、从Ubuntu客户端连接并挂载共享文件夹。

suppose my windows server is YJ104. and hthe work group is "WORKGROUP", and I have created a user name called "bq". 

you'd first share a folder and enables permission for YJ104\bq;, 

to visit hte files from smbclient, you can do is like this:

smbclient //YJ104/share -Ubq -WWORKGROU

and you can ls on files ..

when this is ready, you can mount the files, here is what  you do:

bq@ubuntu:~$ sudo mount -t cifs -o username=bq,workgroup=workgroup,password=password,uid=bq,gid=sudo,file_mode=0640,dir_mode=0750 //YJ104/share /mnt/share


you may need to first make dir /mnt/share

mkdir -p /mnt/share

you can check on the gid, uid of user bq by :

id boqwang


P.S, you may want to add the following line to the /etc/hosts file, so it knows the YJ104

bq@ubuntu:~$ cat /etc/hosts
127.0.0.1	localhost
127.0.1.1	ubuntu
192.168.61.1	YJ104



You may refer to this pages for details on how to troubleshooting 

  Permission denied after successfully mounting a directory with smbfs : http://www.jroller.com/agileanswers/entry/permission_denied_after_successfully_mounting


<think>Hmm, the user is asking about smbclient-like connection methods and alternative software application methods. Let me analyze this carefully. First, I notice the user references three technical sources about smbclient usage patterns - this suggests they're likely a system administrator or IT professional working with SMB/CIFS file sharing. The detailed examples indicate they want practical implementation knowledge rather than theoretical concepts. Looking at the query structure, they specifically want two things: connection methods similar to smbclient (probably meaning CLI-based SMB access) and alternative software solutions. The phrase "应用方式" (application methods) is key here - they need implementation techniques, not just tool names. From memory, the main alternatives to smbclient would include: - Mount.cifs for permanent mounts - Smb4k GUI for desktop users - Python scripts using pysmb or smbprotocol libraries - Curl with smb:// support (as mentioned in reference [1]) - Dedicated file managers like Nautilus or Dolphin The user seems experienced given they referenced Kali Linux tools (ref [2]), so I should include advanced options like API usage. Also worth noting Windows alternatives like NET USE commands since SMB is cross-platform. For connection methods, I should cover: - Interactive CLI (like smbclient's prompt mode) - Single-command non-interactive usage - Permanent mounts - GUI connections - Programmatic access The response should structure these alternatives clearly while keeping it practical. Maybe organize by use case: CLI lovers, GUI users, automation needs etc. The examples from references will be useful - like showing curl smb:// syntax and mount commands. Better include important caveats too: security considerations when storing credentials, version compatibility (SMB1 vs SMB3), and domain vs workgroup differences. The user seems technical enough to appreciate these details. </think>以下是类似`smbclient`的连接方法及替代方案的应用详解,结合SMB协议操作的核心场景: --- ### 一、原生SMB/CIFS连接方法 #### 1. **交互式CLI连接(类smbclient)** ```bash smbclient //服务器IP/共享目录 -U 用户名%密码 ``` - **操作流程**: ```bash smb: \> ls # 列出文件 smb: \> get file.txt # 下载文件 smb: \> put local.txt # 上传文件 smb: \> mkdir backup # 创建目录 smb: \> exit # 退出 ``` #### 2. **单命令非交互模式** ```bash smbclient -c "ls; get file.txt" //192.168.1.10/share -U user%pass ``` - **适用场景**:自动化脚本操作,一次性执行多个命令[^3]。 --- ### 二、替代方案及应用 #### 1. **Linux挂载为本地目录** ```bash # 需cifs-utils支持 sudo mount -t cifs //192.168.1.10/share /mnt/smb -o username=user,password=pass ``` - **特性**: - 文件操作如同本地目录(`cp /mnt/smb/file.txt ~/`) - 需root权限,重启后失效(需配置`/etc/fstab`持久化)[^3] #### 2. **Curl支持SMB协议(需v7.40+)** ```bash curl -u "user:pass" smb://192.168.1.10/share/file.txt -o local.txt ``` - **优势**:直接集成到HTTP工具链,适合简单下载任务[^1] #### 3. **GUI工具** - **Smb4k**(KDE):图形化浏览/挂载SMB共享 - **Nautilus**(GNOME):地址栏输入 `smb://192.168.1.10/share` - **Windows文件管理器**:`\\192.168.1.10\share` 直接访问 #### 4. **编程库集成** ```python # Python示例(pysmb库) from smb.SMBConnection import SMBConnection conn = SMBConnection('user', 'pass', 'client', 'server') conn.connect('192.168.1.10') with open('local.txt', 'wb') as f: conn.retrieveFile('share', '/remote.txt', f) ``` - **适用场景**:自动化备份、自定义文件同步工具 --- ### 三、关键对比 | **方案** | 交互性 | 学习曲线 | 脚本友好 | 权限要求 | |------------------|----------|----------|----------|----------| | smbclient CLI | 高 | 中 | ✓ | 低 | | CIFS挂载 | 无 | 低 | ✓ | 高(root) | | Curl | 无 | 低 | ✓ | 低 | | GUI工具 | 高 | 极低 | ✗ | 低 | | 编程库(如pysmb)| API控制 | 高 | ✓ | 低 | --- ### 四、安全建议 1. **避免明文密码**:使用`-A`参数指定凭证文件 ```bash echo "username=user\npassword=pass" > ~/.smbcred mount -t cifs ... -o credentials=~/.smbcred ``` 2. **协议版本**:强制使用SMBv3(`vers=3.0`挂载参数) 3. **防火墙**:仅允许445/tcp端口访问 > 提示:对于只读访问需求,添加`guest`参数可跳过认证(如`-o guest`)[^3]。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值