Table of Contents

Formatting External Hard Drive

I recommend formatting with the ext4 file system as it is most common on modern Linux systems.

  1. Display all block devices with file system information (the partitions that do not contain information on the file system in use are non-formatted partitions)
     lsblk -f
    
  2. Format a disk partition with ext4 file system
     sudo mkfs -t ext4 /path/to/device
    
  3. Verify the file system change
     lsblk -f
    

Mounting External Hard Drive

  1. Plug in hard drive

  2. List all block devices with the name, size, file system type, mount location, and Universally Unique Identifier (take note of the UUID as it will be needed later on)
     sudo lsblk -o NAME,SIZE,FSTYPE,TYPE,MOUNTPOINT,UUID
    
  3. Take note of the name of desired hard drive name will be listed on far left side

  4. Locate the mount location of the external drive
     sudo mount [NAME] [MOUNT LOCATION]
    
  5. Check to make sure hard drive is mounted
     df -h
    

Enabling External Hard Drive Mount Upon Reboot

  1. Edit filesystem table
     sudo nano -Bw /etc/fstab
    
  2. Below last PARTUUID entry
     UUID=[INSERT UUID] /mnt/USB auto defaults,user,nofail 0 2
    
  3. Press ^X to exit, Y to save changes, and Enter to confirm

  4. Make sure that hard drive will mount upon startup
     sudo reboot
    

Mounting a SMB Share in Ubuntu

This can either be done remotely via SSH from your local machine or directly on the server itself.

  1. Update packages
     sudo apt-get update && sudo apt-get upgrade -y
    
  2. Install CIFS Utilities
     sudo apt-get install cifs-utils -y
    
  3. Create directories where you want network shares to mount (ex: /media/nas)
     mkdir media/nas
    
  4. In home folder (/home/user) create a new text file inside a directory called smb that will contain the username and password of the network share
     nano smb/.smbcredentials
    
  5. Inside text file -
     username=[username-of-server]
     password=[password-of-server]
    
  6. Edit filesystem table
     sudo nano -Bw /etc/fstab
    
  7. Append the following at the bottom of the file
     //SERVER-IP/name-of-share /path-to-mount-location cifs credentials=/path/to/credentials/.smbcredentials,vers=3.0,uid=1000,gid=1000 0 0
    
  8. Mount SMB share type
     sudo mount -a
    

Setting Up Samba

A Samba file server enables file sharing across different operating systems over a network.

Samba Installation

Install the required Samba files

sudo apt-get install samba samba-common-bin

Samba Share Configuration

  1. Edit smb configuration file
     sudo nano /etc/samba/smb.conf
    
  2. At the bottom of the file
     [INSERT LABEL OF HARD DRIVE]
     comment = LABEL OF HARD DRIVE
     public = no
     writeable = yes
     browsable = yes
     path = /path-to-mount-point
     create mask = 0777
     directory mask = 0777
     only guest = no
    
  3. Require a login for server connection
     sudo smbpasswd -a $USER
    

Connect to Server with Login

  1. Have Finder.app active and press Command + K

  2. Type smb://[INSERT IP]

  3. Click Connect

  4. Type in pi as username and your previously chosen password

  5. Click on hard drive label to mount the server

SSH Keys

SSH Keys are stronger than plain text passwords since authentication requires both a private and public key pair.

Creating a SSH Key on Mac

  1. To generate a SSH Key - ssh-keygen -t ed25519

  2. The prompt will ask where you want to store the RSA private and public keys. If you press Enter then both keys will be stored in the .ssh hidden directory.

  3. The next prompt will ask if you want to enter a passphrase. I recommend doing this since leaving this blank will allow anyone who gains control of your private key to login to your servers.

     ~/.ssh/id_rsa - this is your private key (DO NOT SHARE THIS)
     ~/.ssh/id_rsa.pub - this is your public key which you will be copying over to your server
    

Configure SSH To Always Use Keychain

ssh-add --apple-use-keychain ~/.ssh/[your-private-key]

Adding the New SSH Key, so That It Can Get Picked Up for Every Terminal Session Automatically

  1. Create a config file in .ssh folder - touch config

  2. Type the following inside the config file

     Host [ip-address / URL]
       AddKeysToAgent yes
       UseKeychain yes
       IdentityFile ~/.ssh/[your-private-key]
    

    Copying Public Key to Server

     ssh-copy-id -i ~/.ssh/[your-public-key] user@host