# Linux command line for security beginners: files, permissions, ports and curl

Published: 2026-11-24 · Updated: 2026-11-18 · By HackerGPT Team
Canonical: https://hackergpt.org/blog/linux-command-line-for-security-beginners/

> The shell skills security work starts with, run for real: moving around, reading files, permissions that leak a .env, finding what listens on a port, grep pipelines over a log, and curl requests against CyberGym.

**TL;DR:** For security work on Linux you need six things from the shell: move around and see hidden files (`pwd`, `cd`, `ls -la`), read files (`cat`, `head`, `tail`), read and set permissions (`ls -l`, `chmod`), see what runs and what listens (`ps`, `ss -tlnp`), filter text with pipes and `grep`, and send HTTP requests exactly as you mean them with `curl` (`-i`, `-X`, `-H`, `-d`, `-b`). Learn them on a lab machine and a practice target, where a mistake costs nothing.

This is for learners who are starting out in security and have opened a terminal a few times, but not much more. Everything below was run on 18 November 2026: the shell part in a fresh Ubuntu 24.04 container on our own machine, the HTTP part with curl against [CyberGym](https://cybergym.hackergpt.app), our deliberately vulnerable practice app. Point these commands only at machines and sites you own or have written permission to test.

It is item one of Stage 1 on our [hacking roadmap](https://hackergpt.org/learn/roadmap/), and it is the base the rest of [learning hacking from zero](https://hackergpt.org/blog/how-to-learn-hacking/) stands on.

## Why do I need the Linux command line for security?

Because most of what you will test, and most of the tools you will test it with, are driven from a shell. Web servers, containers and cloud machines are commonly administered over a terminal, many scanners and proxies have command-line interfaces, and plenty of CTF challenges hand you a shell rather than a desktop. The skills that matter are not the obscure ones: they are reading what is on a machine, telling who may read it, seeing what is listening on the network, and talking to a web app without a browser in the way.

You do not need to install Linux to start. If you have Docker, this gives you the same disposable machine we used:

```bash
docker run -it --rm ubuntu:24.04 bash
apt-get update && apt-get install -y curl iproute2 procps python3 jq file
```

Our lab had two ordinary users, `alice` and `bob`, and a small app in `/srv/myapp` owned by alice: an `index.html`, a `deploy.sh` script, a `logs/access.log` and a `.env` file holding two made-up secrets. We created the users with `useradd -m -s /bin/bash alice` (and the same for bob) and switched between them with `su - alice`. The versions were curl 8.5.0, iproute2 6.1.0, procps-ng 4.0.4, Python 3.12.3 and jq 1.7.

## How do I move around and read files?

You find out where you are with `pwd`, who you are with `whoami` and `id`, move with `cd`, and list with `ls`. As alice:

```bash
pwd
whoami
id
```

```text
/home/alice
alice
uid=1001(alice) gid=1001(alice) groups=1001(alice)
```

`id` matters more than it looks: the user and groups it prints are exactly what the permission checks below compare against. Now list the app:

```bash
cd /srv/myapp
ls
```

```text
deploy.sh
index.html
logs
```

The `.env` file is missing from that list. `ls` hides every name that starts with a dot, which is also why dotfiles such as `.env` and `.git` are so easy to forget on a server. Add `-a` for all files and `-l` for the long format:

```bash
ls -la
```

```text
total 24
drwxrwxr-x 3 alice alice 4096 Nov 18 22:23 .
drwxr-xr-x 1 root  root  4096 Nov 18 22:23 ..
-rw-rw-r-- 1 alice alice   47 Nov 18 22:23 .env
-rw-rw-r-- 1 alice alice   27 Nov 18 22:23 deploy.sh
-rw-rw-r-- 1 alice alice   15 Nov 18 22:23 index.html
drwxrwxr-x 2 alice alice 4096 Nov 18 22:23 logs
```

To read files, use `cat` for a short file, `head -n 2` for the first lines, `tail -n 1` for the last ones (`tail -f` keeps following a log as it grows), `wc -l` to count lines and `file` to see what a file is before you open it. `less` pages through a long file; `q` quits it.

```bash
head -n 2 logs/access.log
wc -l logs/access.log
file deploy.sh
```

```text
127.0.0.1 - - [18/Nov/2026:21:02:11 +0000] "GET / HTTP/1.1" 200 15
127.0.0.1 - - [18/Nov/2026:21:02:14 +0000] "GET /.env HTTP/1.1" 404 0
6 logs/access.log
deploy.sh: Bourne-Again shell script, ASCII text executable
```

## How do Linux file permissions work?

Every file has an owner, a group, and three sets of permission bits: read (`r`), write (`w`) and execute (`x`) for the owner, for members of the group, and for everyone else ("other"). `ls -l` prints them as a ten-character string, and [`chmod`](https://man7.org/linux/man-pages/man1/chmod.1.html) changes them, either with letters (`u+x`, `o-r`) or with one octal digit per set, where read is 4, write 2 and execute 1.

![The ls -l string -rw-rw-r-- split into file type, owner, group and other bits, with 664 and the 600 that fixes it](https://hackergpt.org/blog/linux-command-line-for-security-beginners/permission-string.webp)

*How to read the `.env` line from the listing above, and what `chmod 600` changes.*

For a directory the same letters mean something slightly different: `r` lets you list the names in it, `x` lets you enter it and reach the files inside. That is why bob, who is not alice, could not even list alice's home folder in our lab:

```bash
ls /home/alice
```

```text
ls: cannot open directory '/home/alice': Permission denied
```

Ubuntu 24.04 creates home directories as `drwxr-x---` (750); its `/etc/login.defs` sets `HOME_MODE 0750`. `/srv/myapp` is not a home directory, though, and it was `drwxrwxr-x`, so anyone could walk in.

### Who may read the .env file?

In our lab, everyone. The `.env` line reads `-rw-rw-r--`, which is 664: the final `r` gives read access to every account on the machine. As bob:

```bash
cat /srv/myapp/.env
```

```text
DB_PASSWORD=change-me
API_KEY=example-not-real
```

Nobody had done anything unusual to get there. Alice's umask (the bits removed from the default permissions of every new file) was `0002`: Ubuntu's `/etc/login.defs` sets `USERGROUPS_ENAB yes`, which turns the default `022` into `002` for a user who has a group of their own, so a file she creates comes out as 664, readable by all. A secrets file needs to be readable by its owner only. As alice:

```bash
chmod 600 .env
chmod u+x deploy.sh
ls -l .env deploy.sh
```

```text
-rw------- 1 alice alice 47 Nov 18 22:23 .env
-rwxrw-r-- 1 alice alice 27 Nov 18 22:23 deploy.sh
```

Bob now gets `cat: /srv/myapp/.env: Permission denied`. The second line shows the execute bit at work: before `chmod u+x`, `./deploy.sh` failed with `Permission denied` even for its owner, and afterwards it ran. If a web server runs under a different user and needs to read the file, put that user in the file's group and use `640` (`-rw-r-----`) instead of opening it to everyone.

To find files that every user can read under a folder, `find` can match on permission bits:

```bash
find /srv/myapp -type f -perm -o=r
```

```text
/srv/myapp/index.html
/srv/myapp/deploy.sh
/srv/myapp/logs/access.log
```

`.env` no longer appears. Whether the other three should be world-readable is a decision per file; the command gives you the list to decide on.

## How do I see which processes are running and which ports are open?

`ps aux` lists every process with its user and command line, `pgrep -a` finds processes by name, and [`ss -tlnp`](https://man7.org/linux/man-pages/man8/ss.8.html) lists TCP sockets that are listening, with numeric ports and, where you are allowed to see it, the process that owns each one. We started Python's built-in web server as alice, serving the app folder:

```bash
cd /srv/myapp && python3 -m http.server 8000 &
ps aux | grep http.server
```

```text
alice       2509  2.0  0.2  25764 18604 ?        S    22:27   0:00 python3 -m http.server 8000
alice       2512  0.0  0.0   3700  1888 ?        S    22:27   0:00 grep http.server
```

The second line is `grep` finding itself, because its own command line contains the word it is looking for. `pgrep -a -f http.server` never lists itself, so it avoids that (it still lists any other process whose command line contains the pattern, such as a shell that started the server). Then the port:

```bash
ss -tlnp
```

As alice, who owns the server:

```text
State  Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0      5            0.0.0.0:8000      0.0.0.0:*    users:(("python3",pid=2509,fd=3))
```

Two things to read here. `0.0.0.0:8000` means the server listens on every network interface, not only on `127.0.0.1`, so anything that can reach the machine can reach the port; `python3 -m http.server --bind 127.0.0.1` would have kept it local. And the `Process` column is only filled in for processes you are allowed to inspect: bob saw the same `LISTEN` line with the column empty, and so did root inside our unprivileged container, until we ran the command with Docker's `--privileged`. On a normal server, `sudo ss -tlnp` is how you see every owner.

### Does chmod 600 stop a web server from serving the file?

No, and our lab showed it: this request went out after `chmod 600`, with `ls -l` still showing `-rw-------`. File permissions decide which *user* may read a file. The web server was running as alice, alice may read her own `.env`, and the server serves whatever is in its folder:

```bash
curl -i http://127.0.0.1:8000/.env
```

```text
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.12.3
Content-type: application/octet-stream
Content-Length: 47

DB_PASSWORD=change-me
API_KEY=example-not-real
```

Bob could no longer `cat` the file, yet anyone on the network could download it. The fix is to keep secrets out of any folder a web server serves, not only to tighten their bits. Python's own documentation says [`http.server` is not recommended for production](https://docs.python.org/3/library/http.server.html); the same mistake with a real server is covered in [exposed .git folders and .env files](https://hackergpt.org/blog/exposed-git-folder-env-file/).

To stop the server, take its PID from `pgrep` and run `kill 2509`. One thing that surprised us: from a script run with `bash -c "... pkill -f http.server ..."`, `pkill` also matched that shell, whose own command line contained the pattern, and killed the script. Killing by PID avoids that.

## How do pipes and grep help with security work?

A pipe (`|`) sends one command's output into the next command, so small tools combine into a question you can ask of any text: a log, a listing, a server's response. `grep` keeps the lines that match a pattern, `cut` and `awk` pick out fields, `sort` and `uniq -c` count. On the lab's access log:

```bash
grep "POST /login" logs/access.log
```

```text
127.0.0.1 - - [18/Nov/2026:21:02:19 +0000] "POST /login HTTP/1.1" 401 32
127.0.0.1 - - [18/Nov/2026:21:02:20 +0000] "POST /login HTTP/1.1" 401 32
127.0.0.1 - - [18/Nov/2026:21:02:22 +0000] "POST /login HTTP/1.1" 200 48
```

Two failed logins and then a success, three seconds apart. How many requests got each status code:

```bash
awk '{print $9}' logs/access.log | sort | uniq -c | sort -rn
```

```text
      2 404
      2 401
      2 200
```

And which paths someone asked for that look like probing for secrets:

```bash
grep -E "\.(env|git)" logs/access.log | cut -d " " -f 7
```

```text
/.env
/.git/config
```

`grep -c` counts matches instead of printing them, `-i` ignores case, `-v` inverts the match and `-r` searches a whole folder. The same pipelines work on curl's output, which is where the next section goes.

## How do I send HTTP requests with curl?

[curl](https://curl.se/docs/manpage.html) sends one HTTP request and prints the response, and every part of the request is a flag: `-X` sets the method, `-H` adds a header, `-d` sends a body, `-b` sends cookies. `-i` shows the response headers along with the body, `-I` sends a HEAD request for headers only, `-v` prints the request curl actually sent, and `-s` hides the progress meter that otherwise appears when the output goes into a pipe or file.

![Which curl flag writes which part of an HTTP request: -X the method, -H a header, -b the Cookie header, -d the body](https://hackergpt.org/blog/linux-command-line-for-security-beginners/curl-request-anatomy.webp)

*One curl command, run with `-v`, and the request it put on the wire.*

If HTTP itself is new to you, [what an API endpoint is](https://hackergpt.org/learn/api-endpoint/) explains the request and response this section sends. Everything below went to CyberGym, which runs [OWASP Juice Shop](https://owasp.org/www-project-juice-shop/); for other legal targets see [where to practise hacking legally](https://hackergpt.org/blog/practice-hacking-legally/).

### What does a GET request and its response look like?

The simplest request is a URL. CyberGym answers its version endpoint with JSON:

```bash
curl -s https://cybergym.hackergpt.app/rest/admin/application-version
```

```text
{"version":"19.1.1"}
```

`-v` shows what curl sent. Lines starting with `>` are the request, lines starting with `<` the response:

```bash
curl -s -v https://cybergym.hackergpt.app/rest/admin/application-version 2>&1 | grep -E "^[<>] "
```

```text
> GET /rest/admin/application-version HTTP/1.1
> Host: cybergym.hackergpt.app
> User-Agent: curl/8.5.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx
< Content-Type: application/json; charset=utf-8
< Content-Length: 20
```

`curl -sI https://cybergym.hackergpt.app/` returns only the headers, which is where you read security headers: the app sent `X-Content-Type-Options: nosniff` and `X-Frame-Options: SAMEORIGIN`, and also `Access-Control-Allow-Origin: *`.

### How do I send a POST request with headers and a JSON body?

Give the method with `-X POST`, the content type with `-H`, and the body with `-d`. A login attempt with a wrong password:

```bash
curl -s -i -X POST https://cybergym.hackergpt.app/rest/user/login \
  -H "Content-Type: application/json" \
  -d '{"email":"nobody@example.com","password":"wrong"}'
```

```text
HTTP/1.1 401 Unauthorized
Server: nginx
Content-Type: text/html; charset=utf-8
Content-Length: 26

Invalid email or password.
```

Two details from the curl manual. `-d` on its own already makes the request a POST, and the manual says of `-X` that "normally you do not need this option"; we keep it for readability. And `-d` sends `Content-Type: application/x-www-form-urlencoded` unless you set the header yourself, which is why the `-H` line is there: an API that expects JSON may reject or misread the body without it.

### How do I log in and send a token or a cookie?

Log in, take the token out of the JSON with `jq`, and send it back on the next request, as a header or as a cookie depending on what the app reads. We registered a throwaway practice account on CyberGym (a `POST` to `/api/Users` with an email, a password and a security answer) and logged in with it:

```bash
TOKEN=$(curl -s -X POST https://cybergym.hackergpt.app/rest/user/login \
  -H "Content-Type: application/json" \
  -d '{"email":"'"$EMAIL"'","password":"'"$PASSWORD"'"}' | jq -r .authentication.token)
```

`$EMAIL` and `$PASSWORD` are your own practice account's; set them first. The token is a JWT of 761 characters, and it is a live session, so keep it out of screenshots and shared notes. Then ask the app who we are, first with the token in an `Authorization` header, then as a cookie:

```bash
curl -s https://cybergym.hackergpt.app/rest/user/whoami -H "Authorization: Bearer $TOKEN"
curl -s https://cybergym.hackergpt.app/rest/user/whoami -b "token=$TOKEN"
```

```text
{"user":{}}
{"user":{"id":41,"email":"linux-cli-1795040686@example.com","lastLoginIp":"0.0.0.0","profileImage":"/assets/public/images/uploads/default.svg"}}
```

The header got an empty user and the cookie got ours: this endpoint reads only the `token` cookie. The basket endpoint behaved the other way round. With the header, `/rest/basket/25` (our own basket id, from the login response's `bid`) returned our empty basket, and without it, `401`. Two endpoints of one app accepted the session in two different places. That is ordinary, and it is the kind of detail you find only by sending the request yourself and changing one thing at a time.

`-c jar.txt` saves the cookies a server sets, and `-b jar.txt` sends them back on later requests. Our jar stayed empty after the login: Juice Shop's login sets no cookie at all, and its web page stores the token as a cookie in the browser with JavaScript, which curl does not run.

Last, two flags for scripting: `-o /dev/null` throws the body away and `-w "%{http_code}\n"` prints the status, which turns a request into a yes-or-no check:

```bash
curl -s -o /dev/null -w "%{http_code}\n" https://cybergym.hackergpt.app/rest/basket/25
```

```text
401
```

## What should I practise next?

Play [OverTheWire Bandit](https://overthewire.org/wargames/bandit/), a free wargame in which each level is a shell puzzle built on the commands above, and read [Everything curl](https://everything.curl.dev/) when you need a flag this article skipped. Then put the two together on a web target: the [web CTF challenges for beginners](https://hackergpt.org/blog/ctf-for-beginners-web-challenges/) walkthrough works CyberGym with curl alone. A command line does not show you every problem a machine or an app has. It shows you exactly what you asked about, which is why the asking is the skill.

## Key takeaways

- Use `ls -la`, not `ls`: dotfiles such as `.env` and `.git` are hidden by default and are the ones that leak.
- Read the last three letters of `ls -l` as "what every user may do", and set secrets to `600` (or `640` with a group) with `chmod`.
- File permissions do not stop a process that runs as the owner from serving a file; keep secrets out of folders a web server serves.
- Check `ss -tlnp` for `0.0.0.0` listeners, and run it with `sudo` to see every process behind them.
- Send requests with `curl -i` and change one flag at a time: the method, a header, the body or a cookie.

## FAQ

### What are the most important Linux commands for hacking beginners?

Learn these first: `pwd` and `cd` to move around, `ls -la` to see every file including hidden ones, `cat` `head` and `tail` to read them, `chmod` to set who may read them, `ps` and `ss` to see what runs and listens, `grep` to filter output and `curl` to talk to a web app. Most advanced tools assume you can already do these.

### What does chmod 600 mean?

It sets a file's permissions to read and write for its owner and nothing for the group or anyone else, which `ls -l` shows as `-rw-------` at the start of the line. Each digit is one set of permissions, owner then group then other, where read is 4, write is 2 and execute is 1. It is the usual setting for a file that holds secrets.

### How do I check which ports are open on my Linux machine?

Run `ss -tlnp` to list the TCP ports your machine is listening on, with numeric port numbers and the process behind each one. Run it with `sudo` to see processes that belong to other users. A local address of `0.0.0.0` or `[::]` means the port accepts connections on every network interface, not only from the machine itself.

### What is the difference between curl -i and curl -I?

`curl -i` sends the request you describe and prints the response headers followed by the body. `curl -I` sends a HEAD request instead and prints only the headers. Use `-I` to check status codes and headers quickly, and `-i` when you also need the body.

### Do I need to install Linux to learn the command line?

No. A virtual machine, Windows Subsystem for Linux or a container started with `docker run -it --rm ubuntu:24.04 bash` gives you a real Linux shell to practise in, and a container is thrown away when you exit. curl itself also runs on macOS and Windows.

## Sources

- [chmod(1), Linux manual page](https://man7.org/linux/man-pages/man1/chmod.1.html)
- [ss(8), Linux manual page](https://man7.org/linux/man-pages/man8/ss.8.html)
- [curl manual page](https://curl.se/docs/manpage.html)
- [Everything curl](https://everything.curl.dev/)
- [Python documentation: http.server](https://docs.python.org/3/library/http.server.html)
- [OWASP Juice Shop](https://owasp.org/www-project-juice-shop/)
- [OverTheWire: Bandit](https://overthewire.org/wargames/bandit/)

Practise these on [CyberGym](https://cybergym.hackergpt.app), or let HackerGPT walk your own site with you at [hackergpt.app](https://hackergpt.app).
