Miscellaneous SysAdmin Guide
Table of Contents
- Formatting External Hard Drive
- Mounting External Hard Drive
- Mounting a SMB Share in Ubuntu
- Setting Up Samba
- SSH Keys
Formatting External Hard Drive
I recommend formatting with the ext4 file system as it is most common on modern Linux systems.
- 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 - Format a disk partition with ext4 file system
sudo mkfs -t ext4 /path/to/device - Verify the file system change
lsblk -f
Mounting External Hard Drive
-
Plug in hard drive
- 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 -
Take note of the name of desired hard drive name will be listed on far left side
- Locate the mount location of the external drive
sudo mount [NAME] [MOUNT LOCATION] - Check to make sure hard drive is mounted
df -h
Enabling External Hard Drive Mount Upon Reboot
- Edit filesystem table
sudo nano -Bw /etc/fstab - Below last PARTUUID entry
UUID=[INSERT UUID] /mnt/USB auto defaults,user,nofail 0 2 -
Press
^Xto exit,Yto save changes, andEnterto confirm - 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.
- Update packages
sudo apt-get update && sudo apt-get upgrade -y - Install CIFS Utilities
sudo apt-get install cifs-utils -y - Create directories where you want network shares to mount (ex: /media/nas)
mkdir media/nas - In home folder (/home/user) create a new text file inside a directory called
smbthat will contain the username and password of the network sharenano smb/.smbcredentials - Inside text file -
username=[username-of-server] password=[password-of-server] - Edit filesystem table
sudo nano -Bw /etc/fstab - 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 - 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
- Edit smb configuration file
sudo nano /etc/samba/smb.conf - 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 - Require a login for server connection
sudo smbpasswd -a $USER
Connect to Server with Login
-
Have Finder.app active and press
Command + K -
Type
smb://[INSERT IP] -
Click
Connect -
Type in
pias username and your previously chosen password -
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
-
To generate a SSH Key -
ssh-keygen -t ed25519 -
The prompt will ask where you want to store the RSA private and public keys. If you press
Enterthen both keys will be stored in the.sshhidden directory. -
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
-
Create a config file in .ssh folder -
touch config -
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