@bobfrankston/mountsmb
v1.1.36
Published
Cross-platform SMB mounting solution for Windows, WSL, and Linux
Maintainers
Readme
mountsmb - Cross-Platform SMB Mounting
A comprehensive SMB mounting solution that provides seamless access to remote filesystems across Windows, WSL, and Linux environments.
Quick Start
# Install globally from npm
npm install -g @bobfrankston/mountsmb
# Mount a remote host's root filesystem
mountsmb beta1
# Mount a specific path
mountsmb pi3a /var/www
# From source directory
node index.js beta1Features
- Automatic hostname resolution from SSH config files
- Platform-aware dual mounting (WSL creates both native and Windows mounts)
- Automatic Samba installation and configuration on remote hosts
- SSH key authentication for secure connections
- Persistent connections that survive reboots
- Cross-platform API for programmatic use
Installation
The script automatically installs required dependencies:
- WSL/Linux:
cifs-utilsfor native SMB mounting - Remote hosts:
sambaserver with automatic configuration
Command Line Usage
Basic Commands
# Mount commands
mountsmb <hostname> # Mount root filesystem
mountsmb <hostname> <path> # Mount specific path
mountsmb beta1 --install-samba # Force Samba reinstallation
mountsmb beta1 --verbose # Enable verbose logging
mountsmb beta1 --debug # Enable debug messages
# Management commands
mountsmb list # Show active mounts
mountsmb unmount beta1 # Unmount specific host
mountsmb cleanup # Remove dead mounts
mountsmb show-mappings # Display hostname mappings
mountsmb sync-config # Sync Windows/WSL configsWindows Wrapper
Use the batch wrapper for Windows:
mountsmb beta1
mountsmb unmount beta1Location: Y:\x\bin\mountsmb.cmd
Configuration
SSH Config Setup
Ensure your SSH config includes host definitions with users:
# Windows: C:\Users\{USER}\.ssh\config
# WSL: ~/.ssh\config
Host beta1
HostName beta1.frankston.com
User root # Required
Host pi3a
HostName pi3a.aaz.lt
User pi # RequiredREQUIRED: A User MUST be specified in SSH config for each host.
JSON Override (Optional)
For hosts not in SSH config:
# ~/.mountsmb/hostnames.json
{
"dev": "development.example.com",
"prod": "production.example.com"
}Access Paths
After mounting, access your files through platform-appropriate paths:
WSL Environment
# Native WSL mount (recommended)
cd /mnt/smb/beta1
ls ~/mounts/beta1 # Convenience symlink
# Cross-platform
ls /mnt/c/drives/smb/beta1 # Windows junction from WSLWindows Environment
REM Native Windows access
cd C:\drives\smb\beta1
dir \\beta1.frankston.com\beta1 REM Direct UNC accessDirectory Structure
Platform-specific mounts:
├── WSL Native: /mnt/smb/{hostname}
├── WSL Symlink: ~/mounts/{hostname} → /mnt/smb/{hostname}
├── Windows: C:\drives\smb\{hostname} → \\{hostname}\{hostname}
└── UNC Direct: \\{hostname}.domain.com\{hostname}Programming API
TypeScript/JavaScript Import
import {
mountSMBHost,
unmountSMBHost,
getActiveMounts,
getHostnameMappings,
getConnectionInfo,
cleanupDeadMounts,
syncHostnameConfigs
} from '@bobfrankston/mountsmb';Core Functions
Mount Operations
// Mount a host's root filesystem
await mountSMBHost('beta1');
// Mount specific path with options
await mountSMBHost('pi3a', { remotePath: '/var/www', installSamba: true });
// Mount with explicit verbose/debug control
await mountSMBHost('beta1', { verbose: false, debug: false }); // Quiet mode
// Unmount
await unmountSMBHost('beta1');Information Queries
// Get all active mounts
const mounts = getActiveMounts();
// Get hostname mappings from SSH config
const mappings = getHostnameMappings();
// Get resolved connection info
const conn = getConnectionInfo('beta1');Maintenance Operations
// Clean up dead mounts
const cleaned = cleanupDeadMounts();
// Sync hostname configs between Windows and WSL
const result = syncHostnameConfigs();Interface Types
interface ConnectionInfo {
user: string; // SSH username
host: string; // Full hostname for connections
mountName: string; // Short name for mount points
remotePath: string; // Remote path being mounted
}
interface MountOptions {
installSamba?: boolean; // Force Samba installation
verbose?: boolean; // Enable verbose logging
debug?: boolean; // Enable debug output
remotePath?: string; // Path to mount (default: "/")
}Troubleshooting
Common Issues
"Command failed: ssh user@host"
- Verify SSH key authentication works:
ssh beta1 - Check hostname resolution:
nslookup beta1.frankston.com
"SMB share is not accessible"
- Force Samba reinstallation:
mountsmb beta1 --install-samba - Check Samba status:
ssh beta1 "systemctl status smbd"
"I/O error accessing /mnt/c/drives/smb/"
- Use WSL native path instead:
/mnt/smb/beta1or~/mounts/beta1 - This is a known WSL limitation with Windows SMB junctions
"Permission denied mounting"
- Install cifs-utils:
sudo apt install cifs-utils - Check sudo privileges for mount commands
Debug Commands
# Show detailed mounting information
mountsmb beta1 --debug
# List all active mounts with status
mountsmb list
# Test hostname resolution
mountsmb show-mappings
# Clean up broken mounts
mountsmb cleanupManual Mount Commands
If the script fails, you can mount manually:
# WSL/Linux manual mount
sudo mkdir -p /mnt/smb/beta1
sudo mount -t cifs //beta1.frankston.com/beta1 /mnt/smb/beta1 \
-o user=root,password=smb_beta1,vers=3.0
# Windows manual mount
net use \\beta1.frankston.com\beta1 smb_beta1 /user:root
mklink /D C:\drives\smb\beta1 \\beta1.frankston.com\beta1Security Notes
- Uses SSH key authentication for initial setup
- SMB passwords are auto-generated per host:
smb_{hostname} - Requires SMB3 with encryption for secure transport
- Samba shares restricted to specific users (no guest access)
Examples
Basic Usage
# Mount beta1's root filesystem
mountsmb beta1
# Access files
ls ~/mounts/beta1/etc/
vim ~/mounts/beta1/root/config.txtAPI Usage
import { mountSMBHost, getActiveMounts } from '@bobfrankston/mountsmb';
// Mount multiple hosts
await mountSMBHost('beta1');
await mountSMBHost('pi3a', { remotePath: '/var/www' });
// Check status
const mounts = getActiveMounts();
console.log(`Active mounts: ${mounts.length}`);Cross-Platform Development
// Works in both Windows and WSL
function getDataPath(hostname: string): string {
if (process.platform === 'win32') {
return `C:\\drives\\smb\\${hostname}\\data`;
} else {
return `/mnt/smb/${hostname}/data`;
}
}
await mountSMBHost('beta1');
const configPath = getDataPath('beta1');
const config = readFileSync(join(configPath, 'app.json'), 'utf8');Additional Tools
For advanced usage and troubleshooting, see companion utilities in /mnt/c/Users/Bob/OneDrive/xfer/bin/linuxbin/:
- setupkeys.ts: Automated SSH key setup and management
- assuressh: Verify SSH connectivity to hosts
- check-mount: Validate mount point status and accessibility
- mount-status: Detailed mount information and diagnostics
Support
- NPM Package: @bobfrankston/mountsmb
- SSH config help:
man ssh_config - Samba documentation: Official Samba docs
