Logout from terminal linux

Linux Logout user / Logoff User Commands

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements pkill
Est. reading time 2m

a) pkill command – Kill processes by name.

b) kill command – terminate or signal a process.

c) logout command – Logout of a login shell. This command can be used by normal users to end their own session.

logout command syntax and example

If you are logged in as nixcraft user and just wanted to exit a login shell type the following command or hit CTRL+D:
$ logout
You will be logout of a login shell session or secure shell session.

Task: Linux logout all other users

If you would like to logout other users, you must login as root user. Next you need to use the pkill command.

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:
    • How to set up Redis sentinel cluster on Ubuntu or Debian Linux
    • How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
    • How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
    • A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
    • How to protect Linux against rogue USB devices using USBGuard

Join Patreon

pkill command syntax

Warning : Do not kill root user or other system level user process. The following example, will kill all process on your server. Do not run the pkill for root user:
pkill -KILL -u root

To see list of logged in user type who or w command:
# who
OR
# w
To logout a user called raj, enter:
# pkill -KILL -u raj
OR
$ sudo pkill -KILL -u raj

See also
  • For more information read our previous “Linux kill and logout users” tutorial.
  • Man pages: pgrep(1)

🐧 Get the latest tutorials on Linux, Open Source & DevOps via

Category List of Unix and Linux commands
Documentation help • mandb • man • pinfo
Disk space analyzers df • duf • ncdu • pydf
File Management cat • cp • less • mkdir • more • tree
Firewall Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04
Linux Desktop Apps Skype • Spotify • VLC 3
Modern utilities bat • exa
Network Utilities NetHogs • dig • host • ip • nmap
OpenVPN CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04
Package Manager apk • apt
Processes Management bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop
Searching ag • grep • whereis • which
Shell builtins compgen • echo • printf
Text processing cut • rev
User Information groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w
WireGuard VPN Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04

Comments on this entry are closed.

Its one of things i hardly ever remember, never mind that i take the effort to write it down, but if you do need it a post like this is worth a million…
thanks

Works in OpenBSD 4.5 also. Great tip.

Whow, thanks for this posting! Just what I needed, highly appreciated!

Thanks, I was looking for such a command

i want to show the login time and logout time of all users then i will sort it according to their name help me pls…

Thanks a lot!
pkill worked fine in the GUI session!
Regards;

Thanks a lot.
I found here very usefull information about my quistions.
Best regards.

what’s the KILL flag do?

thanks, it works me to kill my locked sessions in a server

Hey, Thanks… This is exactly i requried.

Thanks you buddy….I have seen some of your posts regarding Linux commands. They are very useful for beginners like me.

if i logged twice from putty as same user root then if i want to logout one root user then how i would do it.As same user logged twice then in that case if i kill process of root -user then both will get kill…so is their is any ip based parameter to logout one root ?

Mark! do the work!

Wow. What bad information. Lets say you have root logged in under two sessions.

pkill -KILL -u root

That kills all processes owned by root. Meaning most system processes.

Let’s say you have one user in multiple sessions and that user is not root. Well, you just killed both sessions, even if that’s not what you wanted.

This is terrible advice, and the article should be called “Linux Kill All Processes by User”, and have nothing to do with “logging off”.

how The system should send an email alert when the root user has logged out from ssh/terminal.

@Scott, if you know the better command how to logout the user you could write it here, not just come and start wonder here how bed info that is!

How to identify which roles are running in Linux server by using Command line.

How to remotely GUI access linux gateway server .

I want to be able log multiple users off with a message without shutting down. Any thoughts?

ThanKs, comes handy when dude forgot to log out of his guest session here!

Yeah first time i found a usefull answer to my linux questions, : Ctrl + D
😀

Источник

How to Log Out from Ubuntu Session [Beginner’s Tip]

Last updated October 29, 2020 By Abhishek Prakash 3 Comments

How do you log out of Ubuntu?

The answer depends on whether you are using Ubuntu server or desktop. I’ll show you steps for both.

Logout Ubuntu from terminal (for server)

If you are using Ubuntu server and you are confined to the terminal screen, you can use the exit command:

Yes. That’s the way to logout from terminal because there is no logout command in Ubuntu or any Linux distribution. You have commands for shutdown Ubuntu but there is no separate log out command.

You may wonder if there is command for shutdown, command for restart then why there is no Linux command for logout?

The answer lies in the way Linux works. You probably know that Linux is only kernel and you need a shell to interact with the kernel. When you use a terminal or if you log in to an Ubuntu system via SSH, you open a shell session.

If you want to logout from your session, you simply exit the shell. This is why the exit command is equivalent to log out command in Linux.

Log out from Ubuntu desktop (GUI method)

If you are using Ubuntu desktop, you have a graphical interface (called desktop environment). You can use your mouse here.

I am showing the screenshot for the default GNOME desktop but if you are using some other Ubuntu desktop variants like Kubuntu, Lubuntu etc, there should also be a logout button or logout option in the power menu.

To log out from Ubuntu desktop session, go to the top right corner and click to bring the system tray. You should see Power Off / Log Out option. Click on it and it will show the Log Out option.

When you click on the Log Out button, it will open a dialogue box and ask for your conformation. If it receives no input from you, you’ll be logged out in 60 seconds.

That’s it. Now that you know how to log off from Ubuntu session let me tell you a secret tip.

You can use Ctrl+Alt+Del keyboard shortcut in Ubuntu to bring the logout menu. Cool, isn’t it?

Like what you read? Please share it with others.

Источник

4 Ways to Log Out of a Ubuntu Desktop Session

If you are using an Ubuntu system with multiple users and one of the other users asks you to use the system, you have two options for giving the system to him. One is to switch users, and the other is to log out of your user session for the other person. The difference between the two is that when you switch users, your current session continues to run in the background and you can restore your applications to the same state when you log back in. However, when you log off, your current session is terminated and all running applications are stopped. So when you log back in, you will have to reopen all the applications you need. You can choose between switching users and logging off, whichever suits you at the time.

In this article, we will describe four ways using which a user can log out of his/her Ubuntu session:

  • Using the UI
  • Using the Keyboard shortcut
  • Through the application launcher search bar
  • Through the Ubuntu command line, the Terminal

We have run the commands and procedures mentioned in this article on a Ubuntu 20.04 LTS system.

Method 1: Log Out Using the UI

One of the simple ways to log out of your Ubuntu session is to use the menu accessible through the downward arrow located at the top right corner of your Ubuntu screen. This is the menu you will see when you click this arrow:

Click your username and you will be able to see the following two main sub-menu items: Log Out and Account Settings. Click on the Log Out option in order to log out of your current Ubuntu session. The following dialog will display if you do so:

This dialog lets you log out right then by clicking the Log Out button. Otherwise, the system automatically ends your session after 60 seconds unless you press the Cancel button.

Method 2: Log Out Using Keyboard Shortcut

Ubuntu comes with a set of default keyboard shortcuts that allow you to perform commonly used Ubuntu operations with keyboard shortcuts. Logging out, a very common operation is also assigned such a keyboard shortcut. When you press the key combination Ctrl+Alt+Del, the same logout dialog we described above is displayed.

You can see all of these keyboard shortcuts and even create your own using the System Preferences utility. Open the Preferences utility directly from the Keyboard view by typing the word “keyboard shortcuts” into the search bar of your application launcher as follows:

Click on the Keyboard search result and you will be able to see the following view: Advertisement

Method 3: Log Out Using the Application Launcher Search

Another quick method to log out of your session is to use the very useful application launcher search bar. This bar can be accessed by hitting the Super/Windows key on your keyboard.

Enter the keyword “logout” in this search bar and you will see the Log Out utility in the search result as follows:

Click on the Log Out search result and you will be presented with the same Log Out dialog that we described above.

Method 4: Log Out Using the Terminal

For a Terminal-savvy person, the Ubuntu command line also provides a way to log out of your Ubuntu user session.

Open the Ubuntu command line, the Terminal, either through the application launcher search or the Ctrl+Alt+T shortcut.

Then enter the following command in order to end the current user’s login session:

When you run this command, a dialog appears that lets you log out right then by clicking the Log Out button. Otherwise, the system automatically ends your session after 60 seconds unless you press the Cancel button on this dialog.

If you want to directly log out without having to see this dialog, you can make use of the following command:

So, these were some ways you can use to safely log out of your Ubuntu user session so that another user can use the system after you.

Karim Buzdar

About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn

Источник

Читайте также:  Защитить папку от удаления mac os
Оцените статью