Listing shares in linux

Listing available smb shares on a network through the command line in linux

I was wondering if there is a way of listing all the smb servers on a local network (like looking at a network neighborhood in windows) via the command line in fedora.

What do you mean with ‘smb servers’? Do you mean Samba servers, or do you mean all file servers (wether Samba or Windows, wether in my own or in other workgroups/domains) which speak the SMB protocol?

Also, your question’s title (mentioning ‘smb shares’) somewhat contradicts its text (mentioning ‘smb servers’). Which one did you mean?

6 Answers 6

This command is a very little known secret of Samba. It returns IP adresses of all Samba servers in one’s own broadcast domain:

This one returns a list of all NetBIOS names and their aliases of all Samba servers in the neighbourhood (it does a ‘node status query’):

This one returns a list of all IP adresses of SMB servers (that is, Linux+Unix/Samba or Windows) in the neighbourhood:

Finally, all NetBIOS names and their aliases of all SMB servers (Linux+Unix/Samba or Windows):

The command given in the other answer nmblookup -S WORKGROUP does NOT return all Samba or all SMB servers from the neighbourhood. Instead, it returns all servers’ NetBIOS names who happen to be members of a workgroup named ‘WORKGROUP’. The results are independent of the servers’ OS (wether that is Windows, or wether that is Linux/Samba) — and it is a well known fact that sometimes lots of Windows member server are part of a Samba-controlled domain or workgroup. [Yes, it happens that Samba’s default workgroup name is ‘WORKGROUP’. but so what??]. — But the question was ‘How do I get to know all SMB (Samba. ) servers in my network neighbourhood?’

Источник

linux share (samba), how to list all shares with the path to local directory actually shared

Is there a practical way, e.g. net command or other cli to get a list of all shares defined on a Linux server (Ubuntu distribution) listing not only the share name but also the full path to the local shared directory? Without having to look at samba config files or user shares files.

Читайте также:  What can you do with linux certification

4 Answers 4

smbclient [-U ADUser] -L localhost 

Shows the shares, but you have to look this up in your smb.conf to find the path.

ADUser is a domain User that can at least list the samba shares.

Do you have to specifiy an IP or name here, like smbclient -L localhost ? At least for other machines one can say smbclient -L 10.30.40.50 -U ourdomain\\myUsrName

The solution (found thanks to http://ubuntuforums.org/showthread.php?t=1304277&p=8186452#post8186452) is to look at the directory /var/lib/samba/usershares : it contains one file per share, and each file has a line starting with path= containing the local path

Try this script . feel free to improve it

#!/bin/bash while read line; do [[ "$line" =~ ^\[ ]] && name="$line" [[ "$line" =~ ^[[:space:]]*path ]] && echo -e "$name\t$line" done 

At least two ways to do this:

1. mount

$ mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) udev on /dev type devtmpfs (rw,nosuid,noexec,relatime,size=1959288k,nr_inodes=489822,mode=755) . # etc, etc 

With no options, mount will list all mounted file systems. Two options are available:

See man mount for details. An example from my system:

$ mount -l -t cifs //NetgearNAS-3/backup on /mnt/NetgearNAS/backup type cifs (rw,relatime,vers=1.0,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.1.246,soft,unix,posixpaths,serverino,mapposix,acl,rsize=1048576,wsize=65536,bsize=1048576,echo_interval=60,actimeo=1) //SynologyNAS-1/backups on /mnt/SynologyNAS/backups type cifs (rw,relatime,vers=3.1.1,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.1.102,file_mode=0755,dir_mode=0755,soft,nounix,serverino,mapposix,rsize=4194304,wsize=4194304,bsize=1048576,echo_interval=60,actimeo=1,user=seamus) 

2. findmnt

findmnt will list all mounted filesystems or search for a filesystem. The findmnt command is able to search in /etc/fstab, /etc/mtab or /proc/self/mountinfo. If device or mountpoint is not given, all filesystems are shown.

With no options, findmnt provides a neat listing of all mounted filesystems in tree format:

$ findmnt TARGET SOURCE FSTYPE OPTIONS / /dev/sda1 ext4 rw,relatime,errors=remount-ro ├─/sys sysfs sysfs rw,nosuid,nodev,noexec,relatime │ ├─/sys/kernel/security securityfs securityfs rw,nosuid,nodev,noexec,relatime │ ├─/sys/fs/cgroup tmpfs tmpfs ro,nosuid,nodev,noexec,mode=755 . # etc, etc 

findmnt has an extensive set of filtering and formatting options, making it well-suited for use in scripts where the output must be parsed - see man findmnt for details. In this case, if we wish to restrict the output to shares (as in the smb/cifs/nfs sense), the -t option is handy:

$ findmnt -t cifs,nfs4 TARGET SOURCE FSTYPE OPTIONS /mnt/SynologyNAS/rpi_share SynologyNAS-1:/volume1/rpi_share nfs4 rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,se /mnt/NetgearNAS-3/backup //NetgearNAS-3/backup cifs rw,relatime,vers=1.0,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.16 /mnt/SynologyNAS/backups //SynologyNAS-1/backups cifs rw,relatime,vers=3.1.1,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.168. 

Источник

Читайте также:  Установка ocs inventory agent linux

List of all shared folders

Under this path ( /var/lib/samba/usershares ) only some of my shared folders are available. In other machine there is other folders shown under my machine such as: My Printers, print$ and IPC$ which are not listed in the pass in your answer!

Use this command: smbclient -L localhost . A sample of its output is as follow:

Enter username's password: Domain=[WORKGROUP] OS=[Unix] Server=[Samba 4.1.6-Ubuntu] Sharename Type Comment --------- ---- ------- print$ Disk Printer Drivers IPC$ IPC IPC Service (host-name server (Samba, Ubuntu)) hp1320 Printer Hewlett-Packard hp LaserJet 1320 series HP-LaserJet-1200 Printer HP LaserJet 1200 Public Disk Domain=[WORKGROUP] OS=[Unix] Server=[Samba 4.1.6-Ubuntu] Server Comment --------- ------- host-name server (Samba, Ubuntu) Workgroup Master --------- ------- WORKGROUP HOST-NAME 

Are you trying this on the machine that has the share setup? Else change it to the IP address of the server you are trying to read.

@Lokesh I think Tobias' coment was meant to be addressed to you. I'd also mention that this specific error usually means that nobody is listening on 139 and 445 port (samba should be listening on at least one of them). You can check if it's true with ss -an | grep -P "\b(139|445)\b" .

GVFS is the virtual filesystem for the Gnome desktop that allows access to shared drives via SMB, FTP, WebDav, and SFTP. Accessed shares are mounted under ~/.gvfs/ , you can see them there as well.

The command above lists all attached external drives, and network shares, e.g.:

$ gvfs-mount -l Drive(0): 1.5 TB Hard Disk [snip] Mount(0): public on fileserver -> smb://fileserver/public/ Type: GDaemonMount Mount(1): SFTP for bert on server.example.com -> sftp://bert@server.example.com/ Type: GDaemonMount Mount(2): WebDAV as bert on server.example.com -> davs://bert@server.example.com/dav Type: GDaemonMount 

If you add the option -i you get even more information.

For samba shares we have a set of utilities that come with the samba suite:

smbtree is a smb browser program in text mode. It is similar to the "Network Neighborhood" found on Windows computers. It prints a tree with all the known domains, the servers in those domains and the shares on the servers. Manpage

This is the result for sudo smbstatus --shares : Service pid machine Connected at (nothing in the list).

Читайте также:  Astra linux установка драйверов звука

If you browse your own machine in the Network section of Nautilus, you should see all the shares.

In Nautilus, the is a "Browse Netwrok" Item in the sidebar. Inside it, there is only one item: "Windows Network" and inside it there is only one item: "WORKGROUP". If I double click WORKGROUP it asks me for user name and password and if I enter my user name and password for my Ubuntu, it does not accept it! Can you help?

Hit Alt + Ctrl + T to open terminal and run the following command:

At least two ways to do this:

1. mount

$ mount sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime) proc on /proc type proc (rw,nosuid,nodev,noexec,relatime) udev on /dev type devtmpfs (rw,nosuid,noexec,relatime,size=1959288k,nr_inodes=489822,mode=755) . # etc, etc 

With no options, mount will list all mounted file systems. Two options are available:

See man mount for details. An example from my system:

$ mount -l -t cifs //NetgearNAS-3/backup on /mnt/NetgearNAS/backup type cifs (rw,relatime,vers=1.0,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.1.246,soft,unix,posixpaths,serverino,mapposix,acl,rsize=1048576,wsize=65536,bsize=1048576,echo_interval=60,actimeo=1) //SynologyNAS-1/backups on /mnt/SynologyNAS/backups type cifs (rw,relatime,vers=3.1.1,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.168.1.102,file_mode=0755,dir_mode=0755,soft,nounix,serverino,mapposix,rsize=4194304,wsize=4194304,bsize=1048576,echo_interval=60,actimeo=1,user=seamus) 

2. findmnt

findmnt will list all mounted filesystems or search for a filesystem. The findmnt command is able to search in /etc/fstab, /etc/mtab or /proc/self/mountinfo. If device or mountpoint is not given, all filesystems are shown.

With no options, findmnt provides a neat listing of all mounted filesystems in tree format:

$ findmnt TARGET SOURCE FSTYPE OPTIONS / /dev/sda1 ext4 rw,relatime,errors=remount-ro ├─/sys sysfs sysfs rw,nosuid,nodev,noexec,relatime │ ├─/sys/kernel/security securityfs securityfs rw,nosuid,nodev,noexec,relatime │ ├─/sys/fs/cgroup tmpfs tmpfs ro,nosuid,nodev,noexec,mode=755 . # etc, etc 

findmnt has an extensive set of filtering and formatting options, making it well-suited for use in scripts where the output must be parsed - see man findmnt for details. In this case, if we wish to restrict the output to shares (as in the smb/cifs/nfs sense), the -t option is handy:

$ findmnt -t cifs,nfs4 TARGET SOURCE FSTYPE OPTIONS /mnt/SynologyNAS/rpi_share SynologyNAS-1:/volume1/rpi_share nfs4 rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,se /mnt/NetgearNAS-3/backup //NetgearNAS-3/backup cifs rw,relatime,vers=1.0,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.16 /mnt/SynologyNAS/backups //SynologyNAS-1/backups cifs rw,relatime,vers=3.1.1,cache=strict,username=seamus,uid=0,noforceuid,gid=0,noforcegid,addr=192.168. 

Источник

Оцените статью
Adblock
detector