--- title: "Lock active user session on the Linux device" slug: "lock-active-user-session-on-the-linux-device" updated: 2024-10-10T09:34:26Z published: 2024-10-10T09:34:26Z canonical: "help.scalefusion.com/lock-active-user-session-on-the-linux-device" --- > ## Documentation Index > Fetch the complete documentation index at: https://help.scalefusion.com/llms.txt > Use this file to discover all available pages before exploring further. # Lock active user session on the Linux device 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] > 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. 1. Copy and save the contents below to a **UTF-8** editor like **notepad++** OR **Sublime Text** in Windows or **gedit** in Ubuntu. 1. If you are using **notepad++** then use the bottom right panel to change the type to **Unix (LF)**. ![](https://cdn.document360.io/175c0eac-012f-4410-bdc5-ac60794f82d8/Images/Documentation/image-FSW1EZBX.png) 2. Or click [here](https://cdn.document360.io/175c0eac-012f-4410-bdc5-ac60794f82d8/Images/Documentation/Linux_Lock%20Device.txt) to download the file. ```bash #!/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 ``` 3. Follow [our guide](/docs/deploy-linux-shell-scripts-using-scalefusion#step-1-upload-and-deploy-the-script) to upload & publish the script using Scalefusion Dashboard. > [!CAUTION] > Note: > > 1. Some of the scripts and their contents are sourced from internet and yes, our new friend ChatGPT. > 2. Please validate the scripts on a test machine before deploying them on all your managed devices. > 3. 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.