How to Access Raspberry Pi via Hostname and Create File Share with Samba

By default, your Raspberry Pi will not be availble to your network via its Hostname. You could access it via IP address, but that isn’t guaranteed to be static. You’ll also want to setup a file share so that you can code on your desktop machine and easily copy your code to your Pi…or work directly off the Pi via a network share.

You can do both (access via hostname and create a file share) with Samba.

Here’s how:

1. Setup Remote Desktop

Follow the instructions in my How to Remote Desktop into Raspberry Pi (Raspbian Stretch) with RealVNC post. This will allow you to remote into your machine from your Windows desktop.

2. Assign a unique Hostname

  • Go to Raspberry Pi Configuration -> System and set a unique Hostname and click OK.

  • Click Yes to reboot the Pi

3. Install Samba

Open Terminal and run the following:

sudo apt install -y samba

4. Configure Samba

sudo leafpad /etc/samba/smb.conf &

5. Configure Network Hostname

Scroll down to the Global Settings section:

  • Set workgroup to the name of your workgroup or domain name
  • Change ‘wins support’ from ‘no’ to ‘yes’
[global]
workgroup = WORKGROUP
wins support = yes

6. Configure File Share

Scroll down to the bottom of the smb.config file and paste in the following:

[pishare]
comment=pishare
path=/home/pi/
browseable=yes
writeable=yes
only guest=no
create mask=0777
directory mask=0777
public=no

This will share your entire home directory. If you’d like to limit access to a subdirectory, just create a directory and change the ‘path’ variable.

Save smb.config

7. Set File Share Password

Open Terminal and execute the following to set the Samba password for the ‘pi’ user.

This password can be different than the regular Pi user password.

sudo smbpasswd -a pi

You’ll need to enter the password twice.

8. Remote Desktop via Hostname

You can now remote into your Pi via hostname instead of IP. See this post for remote desktop instructions.

9. Access Pi File Share from Windows

You can now access the file share you just created on your desktop machine

  • Open Windows Explorer, type in your Pi hostname and you will see the share

10. Map Network Drive to Share

I like to do this so I can easily access the files without having to type in the Hostname everytime.

  • Right click on ‘This PC’ in Windows Explorer and select ‘Map network drive…’

  • Enter path to Pi share and check ‘Connect using different credentials’

  • Select ‘Use a different account’ and enter ‘pi’ and ‘raspberry’ (or whatever you set your Samba user/password to). Check ‘Remember my credentials’ so you don’t get prompted everytime you access the share.

  • You will now be able to access the share via drive letter

Jon