Mounting remote filesystems with smbfs

 

Mounting remote filesystems with smbfs

From:http://www.debian-administration.org/articles/165

Posted by Steve on Fri 17 Jun 2005 at 11:43

Previously we've covered mounting remote filesystems using OpenSSH which works very well for most Unix servers. But when it comes to remotely mounting filesystems from Windows servers, or desktops, there's only one choice. The Samba file system module, smbfs .

Much like mounting remote filesystems with OpenSSH this involves the use of a kernel module, but unlike shfs there's no need to build this from source yourself.

The Debian kernel packages all come with the smbfs module built already, although if you compile your own kernel from source you might need to enable it yourself.

Samba is a very well known project in the Linux world, it allows you to do a lot of different things but most noticably:

  • Communicate with a Microsoft Windows fileserver, domain server, or printer server.
  • Impersonate a Microsoft Windows fileserver, domain server, or printer server.

Both the K desktop environment (KDE), and the GNOME desktop allow you to explore remote Samba shares, or Microsoft windows shares. However there are times when you cannot use these - for example if you wished to backup a remote machine from a shell script.

For these jobs the Samba File System kernel module, and tools, are a much better fit.

To mount a remote system directly upon your current system you'll need:

  • The smbfs kernel module
  • The smbfs package .
  • A mountpoint - this is just an empty directory.
  • The Name/IP address of the host to connect to.
  • Login credentials to the remote share - both username and password.
  • Local root privileges to do the mount, and load the kernel module.

If you don't already have the smbfs package installed you'll need to install it:

root@mystery:~# apt-get install smbfs

When this is installed you'll also get the samba-common package. If you're not already running a Samba server the installation of this package will ask a couple of questions about your workgroup name, etc. You may safely ignore those questions and just accept the defaults.

Once you have the smbfs package installed you can begin testing things.

As a small example lets assume I wish to mount the "C: " drive of remote machine "recurring.my.flat " to the local machine mystery.my.flat I would begin by loading the kernel module:

root@mystery:~# modprobe smbfs

You can cause this module to be loaded automatically as the machine boots by running:

root@mystery:~# echo 'smbfs' >> /etc/modules

Once the module is loaded I'll create a new directory to be the mount-point:

root@mystery:~# mkdir -p /mnt/recurring

This directory will be where all the remote files will be visible. To actually perform the mounting we have to run:

root@mystery:~# mount -t smbfs -o username=Administrator //recurring/c$ /mnt/recurring

If this command is successful you'll be prompted for the password to make the connection. To avoid this you can also specify the password for the connection on the command line as this example shows:

root@mystery:~# mount -t smbfs -o username=Administrator,password=Password //recurring/c$ /mnt/recurring

An invalid password, or lack of credentials will give you a response similar to this:

22077: session setup failed: ERRDOS - ERRnoaccess (Access denied.)
SMB connection failed

If you receive an error message which is unrelated to authentication you should check the end of the "dmesg " output, by running:

root@mystery:~# dmesg | tail

If the output includes the following text then you're missing the smbfs package:

smbfs: mount_data version 1919251317 is not supported

Once you've successfully mounted the remote system you can explore from the comfort of your Debian machine:

root@mystery:~# cd /mnt/recurring/
root@mystery:/mnt/recurring# ls
arcldr.exe                        Images         System Volume Information
arcsetup.exe                      IO.SYS         six.avi
AUTOEXEC.BAT                      MSDOS.SYS      Untitled.zip
boot.ini                          MyWorks        Untitled.upd
cat.zip                           NTDETECT.COM   Utilities
CONFIG.SYS                        ntldr          Videos
Documents and Settings            pagefile.sys   WINNT
putty.exe                         Program Files  WUTemp

You can also mount the filesystem via /etc/fstab - but note this will include your password in plain text to any local user upon the system:

//recurring/c$  /mnt/recurring  smbfs  defaults,user,noauto,username=Administrator,password=Password  0  0 

To protect your passwords you can instead save them in a file, and pass that along instead - for example you could create the file /etc/recurring.smbpass which contains the username and password to use for the connection:

root@mystery:~# cat >/etc/recurring.smbpass  <<EOF
username=Administrator
password=password
EOF

By changing the permissions this can then be read only by the root user:

root@mystery:~# chmod 600 /etc/recurring.smbpass 
root@mystery:~# chown root.root /etc/recurring.smbpass

With the login details safely secured you can now mount the remote system using them :

root@mystery:/mnt# mount -t smbfs //recurring/c$ /mnt/recurring -o credentials=/etc/recurring.smbpass 

Similarly you can adjust the mount line in /etc/fstab to read:

//recurring/c$  /mnt/recurring  smbfs  defaults,credentials=/etc/recurring.smbpass  0  0 

This will cause the mount to be loaded whenever your machine boots - or if you run as root:

root@mystery:~# mount /mnt/recurring
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ubuntu 16.04 安全加固列表。 Table of Contents Terms of Use ........................................................................................................................................................... 1 Overview ............................................................................................................................................................... 12 Intended Audience ........................................................................................................................................ 12 Consensus Guidance ..................................................................................................................................... 12 Typographical Conventions ...................................................................................................................... 14 Scoring Information ..................................................................................................................................... 14 Profile Definitions ......................................................................................................................................... 15 Acknowledgements ...................................................................................................................................... 17 Recommendations ............................................................................................................................................. 19 1 Initial Setup .................................................................................................................................................. 19 1.1 Filesystem Configuration ............................................................................................................... 19 1.1.1.1 Ensure mounting of cramfs filesystems is disabled (Scored) .............................. 20 1.1.1.2 Ensure mounting of freevxfs filesystems is disabled (Scored)............................ 22 1.1.1.3 Ensure mounting of jffs2 filesystems is disabled (Scored) ................................... 23 1.1.1.4 Ensure mounting of hfs filesystems is disabled (Scored) ...................................... 24 1.1.1.5 Ensure mounting of hfsplus filesystems is disabled (Scored) ............................. 25 1.1.1.6 Ensure mounting of udf filesystems is disabled (Scored) ..................................... 26 1.1.2 Ensure separate partition exists for /tmp (Scored) .................................................... 27 1.1.3 Ensure nodev option set on /tmp partition (Scored) ................................................. 29 1.1.4 Ensure nosuid option set on /tmp partition (Scored) ................................................ 30 1.1.5 Ensure separate partition exists for /var (Scored) ..................................................... 31 1.1.6 Ensure separate partition exists for /var/tmp (Scored) ........................................... 32 1.1.7 Ensure nodev option set on /var/tmp partition (Scored) ........................................ 34 1.1.8 Ensure nosuid option set on /var/tmp partition (Scored) ....................................... 35 1.1.9 Ensure noexec option set on /var/tmp partition (Scored) ...................................... 36 1.1.10 Ensure separate partition exists for /var/log (Scored) .......................................... 37 1.1.11 Ensure separate partition exists for /var/log/audit (Scored) ............................. 39 1.1.12 Ensure separate partition exists for /home (Scored) .............................................. 41 1.1.13 Ensure nodev option set on /home partition (Scored) ........................................... 42

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值