Metasploit’s jobs -k stops specified background jobs; sessions -k terminates specified sessions. Their identifiers belong to separate inventories. For an authorized lab, list both, match each intended object, remove session-dependent configuration, and verify the resulting state. A successful termination message does not prove that the entire lab has been reset.
Key takeaways
- Match job IDs and session IDs separately before using a termination command.
- Returning a session to the background leaves it available.
- Remove session-dependent forwards and routes while the required connection is available.
- Preview session search results before combining the filter with termination.
- Record remaining artifacts and reset responsibilities after checking the live inventories.
What do Metasploit’s jobs -k and sessions -k commands control?
jobs -k acts on background module jobs. sessions -k acts on active sessions identified by session ID. Similar option letters do not make the objects interchangeable, and an identifier copied from the wrong list can select the wrong thing.
Rapid7’s Jobs documentation describes jobs as modules running in the background. A listener or another background module can continue doing work while you use the console. Its job ID identifies that activity, not an interactive connection to a particular target.
Sessions identify connections you can interact with, such as a Meterpreter session or a shell. The framework command source defines separate session listing, interaction, and termination options. Read the help in your installed build before using online examples; the upstream documentation follows ongoing development.
Imagine your lab has a background handler and an established session. The handler’s job ID and the connection’s session ID need separate labels in your notes. Even if their displayed values happen to match, that coincidence is not evidence that either command controls both objects.
This distinction belongs in the practical foundation behind Metasploit skills for cleared penetration testers. Cleanup demonstrates whether you understand the state you created, including what remains after a connection closes.
What should you inventory before stopping anything?
List background jobs, active sessions, and framework routes before changing them. Record which entries belong to the authorized exercise, their purpose, and their dependencies. Preserve the initial state so your final checks have something concrete to compare against.
jobs -l
sessions -l
route print
Run these at the framework console. Include the prompt and framework instance in your saved notes. Output copied from an earlier run or another console is a poor basis for choosing a live termination target.
For jobs, record the module name and available listener or payload settings. For sessions, record the ID, type, host identity, and connection information. For routes, connect each destination and session gateway to the lab diagram.
Add an ownership column to the worksheet. Mark your exercise entries, entries another learner or operator needs, and anything unresolved. In a shared environment, ambiguity is a reason to contact the lab owner before selecting the object, even when your exercise is authorized.
Keep the worksheet open. If a teammate still needs a proxy for an approved verification task, your final state should identify the surviving proxy job, its owner, the task it supports, and the person responsible for stopping it after that task, so the handoff does not depend on someone remembering a verbal exception.
A repeatable Kali practice workflow should retain this inventory alongside the activity log. Sanitized notes can also become interview evidence: the useful part is your explanation of ownership and dependencies, not a count of open connections.
How do you match an identifier to the intended lab object?
Read the row and inspect its details immediately before acting. Match the object’s identity and purpose to your exercise record, then use the command for that inventory. Avoid copying an ID from a transcript and assuming it still identifies the same object.
For a job, jobs -i JOB_ID requests details about the selected job. Here and below, uppercase ID labels are placeholders to replace with identifiers from your current inventory. They are not literal arguments to paste.
For a session, use the active session listing and, when useful, its verbose output. Host, session type, and connection information should agree with the lab record. A vague name alone is insufficient when several practice targets look similar.
| Object | Inspect | Selected termination or removal |
|---|---|---|
| Background module job | jobs -l, then job details |
jobs -k JOB_ID |
| Active session | sessions -l, with verbose details if needed |
sessions -k SESSION_ID |
| Framework route | route print |
Remove the matching destination and session route |
| Session port forward | portfwd list in the relevant session |
Delete the intended forward using installed help |
Record the reason for each action before executing it. “Stop my exercise handler” is reviewable when linked to its current module details. “Kill the usual ID” leaves a teammate unable to tell whether the correct object was selected.
How should you stop a selected job?
Inspect the current job, confirm it belongs to your exercise, then use jobs -k JOB_ID with its actual identifier. List jobs again afterward. Check sessions independently instead of treating a stopped background module as proof that its related connections are gone.
The lowercase -k option targets specified job IDs; uppercase -K stops all running jobs. The broader operation can include jobs outside your exercise. Prefer explicit selection when the intended cleanup boundary is narrower than the whole framework instance.
Decide the sequence from the dependency record. A listener that can accept new exercise connections may need to stop before you finish closing sessions. A proxy supporting a final approved cleanup action may need to remain until that action is complete.
After stopping the selected job, record its absence from the job list. If it was a listener and the exercise requires verifying that the listener is closed, use the lab’s approved inspection method as well. The inventory and the expected behavior are related checks, with different evidence.
If an object reappears, preserve the output and identify the source before repeating termination. The Jobs documentation includes saved handler startup behavior, so stopping current activity should not be treated as a guarantee about future console starts. Have the lab owner review any saved startup configuration included in the exercise.
What must happen before you close sessions and dependent routes?
Finish required session-dependent cleanup while the connection is still available. Review forwards and routes, remove intended exercise entries, then terminate the selected session. Inspect routing again after closure, including any dependencies through that pivot.
Rapid7’s pivoting documentation treats framework routes, port forwarding, and external-tool proxy access as separate mechanisms. Include each mechanism you created in the inventory. Closing an interaction window is not an inventory of those mechanisms.
For a forward, inspect portfwd list in the relevant session and remove the intended mapping using its help. For routes, check the destination, mask, and session gateway. Avoid a blanket flush if other work needs entries in the same framework.
The session-manager source removes associated framework routes when deregistering a session that implements the communication interface. You should still verify the table. This automatic behavior is not a promise that closing a session reverses every host change or external configuration.
Use sessions -k SESSION_ID for the selected session, replacing the placeholder with the current verified ID. Then list active sessions again. If the command fails or the connection is unresponsive, record the actual result and arrange the required reset with the owner.
Backgrounding is different. Rapid7’s Meterpreter command reference distinguishes background from exit or quit. Returning to the framework prompt does not, by itself, mean the session has terminated.
When is filtered session cleanup appropriate?
Use filtering to inspect a known subset of sessions, then verify every match before termination. The session documentation supports restricting kill-all to search results, but a technically valid filter can still select sessions outside your exercise.
Rapid7’s Managing Sessions documentation lists searches by session ID, session type, and last check-in. It explains that combining --search with --kill-all restricts termination to the matching results.
Preview the search by itself first. Compare the returned host identities and IDs with your cleanup worksheet, and repeat the preview if the live state changes. For a small beginner lab, selecting verified individual IDs can be easier to audit than constructing a broad search.
A type-only filter can match every Meterpreter session in the instance, including someone else’s exercise. A stale check-in suggests a connection to investigate; it does not establish ownership or permission to close it. Keep those decisions separate.
Do not transfer session-filter assumptions to the Jobs interface. Its documentation says the job search-filter option is currently ignored. Use job details and explicit IDs instead, and confirm your installed build’s help before depending on filtering behavior.
What proves cleanup is complete enough for handoff?
Compare fresh jobs, sessions, and route inventories with the intended final state. Document any remaining listener, forward, host artifact, or reset requirement. An honest handoff distinguishes observed removal from work that still needs the lab owner’s verification.
Repeat the initial inspection commands and annotate expected survivors. In a dedicated disposable lab, the expected final state may be empty inventories. In a shared instance, unrelated entries may properly remain. The cleanup target comes from the exercise plan.
Review the activity log for test files, changed settings, temporary accounts if any were authorized, and local proxy configuration. Record which items were reverted, which require a snapshot restore, and who owns the remaining action. Preserve authorized test evidence according to the lab’s instructions rather than deleting logs to make the environment appear untouched.
This kind of closeout supports a cleared penetration-testing career because it makes your decisions explainable. In an interview, describe the dependency that determined your cleanup order and the check that established the final state.
Frequently Asked Questions
Does stopping a job close every related session?
Treat jobs and sessions as separate inventories. After stopping the intended background job, inspect active sessions and close only those selected for your exercise. The job termination result alone does not establish the session state.
Does backgrounding a Meterpreter session terminate it?
No. Backgrounding returns control to the framework while leaving the session available. Use the appropriate session termination command when closure is intended, then verify the active session list.
Can I use a session-type filter with kill-all?
The session documentation supports restricting kill-all to search matches. Preview and verify those matches first. Session type alone does not identify which connections belong to your authorized exercise.
What should I record if a target cannot be restored?
Record the affected lab asset, observed residual state, attempted cleanup, and required owner action. Before your next exercise, create a cleanup worksheet with separate job IDs, session IDs, dependencies, and verification results.
