SSH runs remote shells and copies files. Bash scripts often wrap ssh and scp for deploys—prefer keys over passwords.
Remote command
ssh user@host "hostname && uptime"
ssh -i ~/.ssh/id_ed25519 deploy@prod "sudo systemctl status nginx"Quote remote commands so local shell does not parse them first.
Copy files
scp local.txt user@host:/tmp/
scp -r ./dist user@host:/var/www/app/-r recurses for directories—verify destination paths to avoid overwriting wrong trees.
Config file
~/.ssh/config can define Host aliases, IdentityFile, and ProxyJump—reduces typing and documents team conventions. Never share private keys; use Tools docs for key generation.
Important interview questions and answers
- Q: Why quote remote commands?
A: Local shell would otherwise split on spaces and expand globs. - Q: scp vs rsync?
A: scp is simple; rsync adds delta sync—both common in Bash deploy scripts.
Self-check
- What flag selects an identity file for ssh?
- What scp flag copies directories recursively?
Tip: Use SSH keys with passphrase + agent—document in Tools.
Interview prep
- Quote remote command?
Prevent local shell from parsing remote words.
- scp -r?
Recursive copy for directories.