Skip to content

Lab 01-05 · Secure your router: identity, users, SSH keys and services

MTCNA

Module 1 · Introduction. Official course slides 68–77: router identity (LAB, slide 69), RouterOS users (LAB, slide 72), SSH keys (LAB, slide 73, optional) and RouterOS services (LAB, slide 77).

Every winter, news sites publish the list of the most used passwords of the year, and every year 123456 and admin are near the top. Now picture a router that everybody in a school manages with the user admin, the same password, and every door open: web, Telnet, FTP, API... When something breaks, who did it? When a password leaks, which door did the attacker use?

In this lab you turn a factory-fresh router into a tidy one: it gets a name, every person gets their own user, you log in with a key instead of a password, and every door you do not use gets closed.

What you will learn

  • Give a router an identity and see where it shows up
  • Create a personal user with full rights and demote admin to the read group
  • Understand groups and policies (what each user may do)
  • Log in with an SSH key pair instead of a password
  • Disable unused services and restrict the rest with available from
  • Avoid the trap of locking yourself out while doing all of this

One analogy: your router is a house

Router idea In the house
Identity the name on the doorbell
User a person who has a key
Group the kind of key: a full key, or one that only opens the living room
Password a code you type at the door: anyone who learns it gets in
SSH key pair a physical key cut just for you: the lock (public key) stays on the door, the key (private key) never leaves your pocket
Services the doors and windows: front door (SSH), garage (WinBox), window (web)...
Available from a door that only opens for people already inside the garden (the LAN)

Identity

The identity is the router's name. It appears in the CLI prompt ([admin@13_JohnDoe] >), in the WinBox title bar, in neighbour discovery (lab 01-01) and in backup file names (lab 01-06).

When you manage 30 routers, the identity is what stops you from rebooting the wrong one.

Users, groups and policies

A user is an account to log in with. Each user belongs to a group, and the group's policies say what its members may do.

RouterOS comes with three groups:

Group Can do Typical person
full everything, including managing users the network administrator
write change the configuration, but not manage users a technician
read look, but not change someone who monitors, an auditor

Some policies inside a group: read, write, policy (manage users), ssh, winbox, web, ftp, reboot, sensitive (see secrets). You can create your own groups by ticking exactly the policies you want.

Why not keep using admin?

Everybody knows the user name admin, so an attacker only has to guess the password. Personal users also leave a trail: the log says "user john logged in", not "admin logged in" (who?).

SSH keys

An SSH key pair is two linked files: a private key that stays on your laptop, and a public key that you give to the router. The router lets in whoever proves they hold the private key, without any password crossing the network.

flowchart LR
    subgraph L["<b>Your laptop</b>"]
        PRIV["private key<br>(the key in your pocket)"]
        PUB["public key<br>(a copy of the lock)"]
    end
    PUB -- "1 · upload (scp)" --> R["<b>Router</b><br>2 · import it for user john"]
    PRIV -- "3 · ssh -i: prove you have the key" --> R

RouterOS 7 detail: once a user has a key, SSH passwords stop working for that user

The router's SSH server has password-authentication=yes-if-no-key by default (IP → SSH). So as soon as john has a key, SSH logins for john must use the key. WinBox and WebFig still use the password. Keep the private key safe!

Services

A service is a program on the router that waits for connections on a port: SSH on 22, Telnet on 23, web (WebFig) on 80, WinBox on 8291, API on 8728...

Service Port What it is Keep it?
ssh 22 secure CLI yes
winbox 8291 WinBox GUI yes, from the LAN only
www 80 WebFig, unencrypted no (in this lab)
www-ssl 443 WebFig over HTTPS off by default
telnet 23 CLI, unencrypted no
ftp 21 file transfer, unencrypted no (unless you need it)
api / api-ssl 8728 / 8729 for programs that configure the router no (unless you use them)

Every open service is a door an attacker can knock on. The rule: disable what you do not use, restrict what you keep (with available from, the list of addresses allowed to connect), and change default ports if you like.

The scenario

flowchart LR
    YOU["<b>Your PC</b><br>ssh, ssh-keygen, scp"] -- "management port<br>(ether1, lab plumbing)" --> R1["<b>r1</b><br>bridge1 192.168.88.1/24"]
    R1 -- "ether3 — eth1" --- PC1["<b>pc1</b><br>browser (curl)<br>192.168.88.10"]
Node Role Address
r1 the router to secure, fresh out of the box LAN bridge1 192.168.88.1/24
pc1 a laptop on the LAN, used to test WebFig 192.168.88.10
your PC the laptop you manage the router from (SSH, keys) via the lab's management network

Port names in the virtual lab

On a real hAP the Internet port is ether1; in the virtual lab ether1 is reserved for the lab itself, so the Internet port is ether2 and the LAN ports start at ether3. Never touch ether1.

Start the lab

Download the lab files and unzip them: 01-05-identity-users-services.zip. Open a terminal inside the 01-05-identity-users-services folder.

sudo containerlab deploy -t topology.clab.yml
ssh admin@clab-mtcna-01-05-r1                 # password: admin
docker exec -it clab-mtcna-01-05-pc1 bash      # the LAN laptop

Step 1 · Name your router

Why: the course asks for the format YourNumber_YourName, e.g. 13_JohnDoe, so the trainer can tell 20 routers apart.

In WinBox: System → Identity. On r1 (use your number and name, one word, no spaces):

/system identity set name=13_JohnDoe

Expected: the prompt changes immediately to [admin@13_JohnDoe] >. In WinBox the title bar shows the identity in brackets, like admin@192.168.88.1 (13_JohnDoe) - WinBox ....

Check yourself

Name two other places (besides the prompt) where the identity appears.

Done when: your prompt shows your identity.

Step 2 · Create your personal administrator

Why: from now on you will log in as you, not as admin.

In WinBox: System → Users → +, Name john, Group full, Password. On r1 (use your own name and a password you can remember; write both down):

/user add name=john group=full password="Lab-Pass-13"
/user print

Now open a second terminal and log in as your new user:

ssh john@clab-mtcna-01-05-r1

Expected: prompt [john@13_JohnDoe] >. Keep this window open.

Check yourself

Why is it important to test the new user before touching admin?

Done when: you are logged in as your new user in a second window.

Step 3 · Demote admin to read-only

Why: the well-known name admin should not be able to change anything.

In WinBox: System → Users, double-click admin, Group read. In the john window:

/user set admin group=read
/user print

Now, in the admin window, try to change something:

/system identity set name=hacked

Expected: not enough permissions (9). Admin can still look (/ip address print works), but cannot touch.

The lock-out trap

If you demote admin while it is your only full user, nobody can change the router any more: you would need a reset. That is why step 2 comes first.

Check yourself

Which group would you give to a classmate who only has to watch the traffic graphs?

Done when: admin gets not enough permissions when it tries to change the identity.

Step 4 · Log in with an SSH key (optional LAB, slide 73)

Why: a key cannot be guessed like a password, and nothing secret travels over the network.

On your PC (not in the router), create a key pair. Press Enter at the passphrase question for this lab (in real life, use a passphrase):

ssh-keygen -t ed25519 -f ~/.ssh/mtcna_lab -C john@laptop
ls ~/.ssh/mtcna_lab*

Expected: two files, mtcna_lab (private, never share it) and mtcna_lab.pub (public). On Windows, PuTTYgen does the same.

Upload the public key to the router (WinBox: drag it onto Files):

scp ~/.ssh/mtcna_lab.pub john@clab-mtcna-01-05-r1:

Import it and attach it to your user. In WinBox: System → Users → SSH Keys → Import SSH Key. In the john window:

/user ssh-keys import public-key-file=mtcna_lab.pub user=john
/user ssh-keys print

Expected: one key, user john, type ed25519. The .pub file disappears from Files: RouterOS keeps it in its configuration now.

Log in with the private key:

ssh -i ~/.ssh/mtcna_lab john@clab-mtcna-01-05-r1

Expected: you are in, and nobody asked for a password.

Check yourself

Try ssh -o PubkeyAuthentication=no john@clab-mtcna-01-05-r1. What happens, and why? (Read the warning in the SSH keys section above.)

Done when: you log in as john with the key.

Step 5 · Close the doors you do not use

Why: the course's services LAB (slide 77): open WebFig, disable www, refresh, and see it die.

First, on pc1, open WebFig:

curl -s http://192.168.88.1/ | grep -i title

Expected: <title>RouterOS</title>.

In WinBox: IP → Services, select www, click Disable. Do the same with telnet, ftp, api and api-ssl. Then double-click winbox and set Available From to 192.168.88.0/24. On r1 (as john):

/ip service disable www,telnet,ftp,api,api-ssl
/ip service set winbox address=192.168.88.0/24
/ip service print

Expected: an X on the five disabled services, and 192.168.88.0/24 in the ADDRESS column of winbox.

"Refresh the browser" on pc1:

curl -m 4 http://192.168.88.1/

Expected: Failed to connect to 192.168.88.1 port 80. The window is closed.

Do not disable ssh in the virtual lab

SSH is how you reach the router here. On a real router, disabling the service you are connected through, or restricting it to the wrong addresses, locks you out: use safe mode (Ctrl+X, lab 01-01).

Check yourself

Why are Telnet, FTP and www especially dangerous on a network you do not control, like a café's WiFi?

Done when: WebFig no longer answers and only ssh and winbox (LAN only) remain enabled among the main services.

Check your work

CLAB_EXEC="docker exec" ./check.sh

All lines PASS, last line Lab 01-05 SOLVED.

If something goes wrong

Symptom Likely cause Fix
The identity looks odd or is cut in the prompt spaces or symbols in the name (they need quotes) use the course format, one word: 13_JohnDoe
New user cannot log in typo in the password, or the user is in a group without ssh /user print detail from a full user; /user set john password=...
not enough permissions as john john is not in the full group as a full user: /user set john group=full
Nobody can change anything admin demoted while it was the only full user destroy and redeploy the lab (on real hardware: reset)
Permission denied (publickey) for john john has a key, so SSH passwords are refused use ssh -i ~/.ssh/mtcna_lab john@...
Key import: no such item the .pub file name is wrong or the upload failed /file print, check the exact name
WebFig still answers you disabled www-ssl instead of www /ip service print, disable www

Clean up

sudo containerlab destroy -t topology.clab.yml --cleanup

Key takeaways

  • The identity names the router in the prompt, WinBox title, neighbour list and backup names: use Number_Name in class.
  • Every person gets their own user; the group (full, write, read, or your own) decides what they may do through its policies.
  • Create and test your personal full user before demoting admin to read, or you lock yourself out.
  • An SSH key pair replaces the password: the public key goes to the router, the private key never leaves your laptop. In RouterOS 7 a user with a key can no longer use an SSH password.
  • Services are doors: disable the unused ones (www, telnet, ftp, api...) and restrict the rest with available from.

Quick check

1. Where does the router identity appear?
  • In the CLI prompt and the WinBox title bar
  • Only in the System → Identity window
  • In the router's IP address
  • In the MAC address of every port

The identity shows in the prompt ([admin@13_JohnDoe] >), the WinBox title bar, neighbour discovery and backup file names. It does not change any address.

2. Which default group can look at the configuration but not change it?
  • read
  • write
  • full
  • admin

The read group can print everything but has no write policy. write can change the configuration, full can also manage users. admin is a user, not a group.

3. Why must you create and test your own full user before demoting admin?
  • Otherwise no user could change the router any more
  • RouterOS refuses to demote admin while you are logged in
  • The new user only works after admin is demoted
  • Demoting admin deletes all the other users

If admin is your only full user and you move it to read, nobody can change the configuration (or undo the change). Test the new full user first, in a second window.

4. In an SSH key pair, which part do you upload to the router?
  • The public key, the file ending in .pub
  • The private key, so the router can check it
  • Both files, so the router has a complete copy
  • Neither: the router generates its own pair

The public key is like a copy of the lock: safe to hand out. The private key never leaves your laptop; you use it with ssh -i to prove who you are.

5. After importing a key for john, why does ssh john@router with the password fail?
  • RouterOS only allows SSH passwords for users without a key
  • Importing a key deletes the user's password
  • The SSH service is disabled after a key import
  • john was moved to the read group by the import

The SSH server's default is password-authentication=yes-if-no-key: once a user has a key, SSH logins for that user must use it. The password still works in WinBox and WebFig.

6. You disable the www service. What happens when you reload http://192.168.88.1?
  • The browser cannot connect: WebFig is gone
  • WebFig asks for the SSH key instead of a password
  • WebFig opens in read-only mode
  • The browser is redirected to WinBox

The www service is the program listening on port 80 for WebFig. Disabled, nothing answers on that port, so the connection fails.

7. A café owner asks you to harden their MikroTik. Which two changes fit this lab?
  • Disable telnet, ftp and www because they are unencrypted
  • Allow WinBox only from the shop's LAN with available from
  • Give every employee the admin user and password
  • Enable the API service so it can be managed from the Internet

Disable unused, unencrypted services and restrict the ones you keep with available from. Sharing admin and opening more doors to the Internet do the opposite.

Your router now has a name, real users and only the doors it needs. Next lab: back it all up, wipe it, and bring it back.