Created
June 3, 2022 13:48
-
-
Save cherts/1832cc204c5bae8ff4f6eb442504bef2 to your computer and use it in GitHub Desktop.
Kill user session via loginctl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # Program: Kill user session via loginctl <kill_session.sh> | |
| # | |
| # Author: Mikhail Grigorev <sleuthhound at gmail dot com> | |
| # | |
| # Current Version: 1.0.1 | |
| # | |
| # License: | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| # | |
| USER_LOGIN=$1 | |
| if [ -n "${USER_LOGIN}" ]; then | |
| USER_SESSION_LIST=($(loginctl 2>/dev/null | grep ${USER_LOGIN} | awk -F' ' '{print $1}' | sed 's/^[ \t]*//;s/[ \t]*$//' 2>/dev/null)) | |
| for ((i=0; i<${#USER_SESSION_LIST[@]}; i++)); do | |
| echo "Terminate session: ${USER_SESSION_LIST[$i]}" | |
| loginctl terminate-session ${USER_SESSION_LIST[$i]} | |
| done | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wget -O - https://gist.githubusercontent.com/CHERTS/1832cc204c5bae8ff4f6eb442504bef2/raw/kill_session.sh | bash /dev/stdin "myuser_login"