SSH & Remote Administration
Stop ssh-copy-id from failing when your server has non-standard paths
🧩 The Challenge
Setting up a new box usually means firing off ssh-copy-id, but I’ve spent way too long debugging why it dies on hardened servers where the home directory isn’t where the local admin expects it to be. You get a cryptic permission error and then you’re stuck doing it all manually.
💡 The Fix
Just pipe the local public key directly into the remote authorized keys file using standard shell redirection instead of relying on the helper script. It bypasses the assumptions the helper makes about your remote environment.
cat ~/.ssh/id_rsa.pub | ssh user@remote-host "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"
⚙️ Why It Works
By stringing these commands together, you ensure the directory and file permissions are correct before the key even lands on the disk. It’s way more reliable than letting a script guess your folder structure.
🚀 Pro-Tip: Alias this as ‘pubkey-push’ in your bashrc and you’ll never look back.
Linux Tips & Tricks | © ngelinux.com | 11/29/2026
