Interview Q&A / Linux & Shell
Linux & Shell interview questions
Permissions, processes, pipes and the commands you are expected to know cold.
Prefer rapid revision? Practise Linux & Shell short interview answers →
- How do you see which ports are listening and which process owns them?
Run sudo ss -tulpn. It lists TCP and UDP listening sockets with numeric ports and the owning process name and PID. ss has replaced the older netstat on modern Linux, and you can filter with grep or an expression like sport = :8080.
BeginnerQuick answer1 min read - How do you send GET and POST requests with curl?
curl URL sends a GET. For a POST with JSON use curl -X POST -H 'Content-Type: application/json' -d '{...}' URL. Adding -d already makes the request a POST, and -i or -v shows the response headers.
BeginnerQuick answer1 min read - How does SSH key-based login work, and how do you set it up?
You generate a key pair with ssh-keygen, keep the private key on your machine and copy the public key to the server's ~/.ssh/authorized_keys with ssh-copy-id. The server then challenges you to prove you hold the private key, so no password crosses the network.
BeginnerQuick answer1 min read - How do you check whether a remote port is reachable from a Linux machine?
Use nc -zv host port for a quick TCP check, or curl -v telnet://host:port, or bash's /dev/tcp. A refused connection means nothing listens there; a timeout usually means a firewall or routing problem. ping only tests ICMP, not ports.
IntermediateQuick answer1 min read - What do the curl flags -s, -L, -o, -f and -I do?
-s hides the progress meter, -L follows redirects, -o saves the body to a file, -f makes curl fail with a non-zero exit code on HTTP errors, and -I fetches only the headers. A common combination in scripts is curl -fsSL.
IntermediateQuick answer1 min read - What is the difference between scp and rsync for copying files over SSH?
Both copy over SSH. scp sends the whole file every time, while rsync compares source and destination and sends only the differences, can resume, and can preserve permissions and delete extras. Use scp for one-off copies and rsync for repeated syncs and large folders.
IntermediateQuick answer1 min read - What is SSH local port forwarding, and when is it used?
ssh -L local_port:target_host:target_port user@server opens a port on your machine and tunnels traffic through the SSH server to the target. It lets you reach a service, such as a private database, that is only accessible from the server's network.
AdvancedQuick answer1 min read