- 10 Oct 2024
- 1 読む分
- 印刷する
- PDF
Lock active user session on the Linux device
- 更新日 10 Oct 2024
- 1 読む分
- 印刷する
- PDF
The following script locks the currently active user session on a Linux system. This might be used to quickly secure a session, such as when stepping away from the computer.
Note:
Repeat execution of scripts is not supported, hence please delete and re-upload the script and Publish each time you would want to lock device.
Copy and save the contents below to a UTF-8 editor like notepad++ OR Sublime Text in Windows or gedit in Ubuntu.
If you are using notepad++ then use the bottom right panel to change the type to Unix (LF).
Or click here to download the file.
#!/bin/bash # Find the active session session_id=$(loginctl list-sessions --no-legend | awk '{print $1}') if [ -n "$session_id" ]; then # Lock the active session loginctl lock-session "$session_id" echo "Locked session $session_id" else echo "No active session found." fi
Follow our guide to upload & publish the script using Scalefusion Dashboard.
Note:
Some of the scripts and their contents are sourced from internet and yes, our new friend ChatGPT.
Please validate the scripts on a test machine before deploying them on all your managed devices.
Scalefusion has tested these scripts, however Scalefusion will not be responsible for any loss of data or system malfunction that may arise due to the usage of these scripts.