How To: Kill A User Session

Today’s article won’t be useful for many of my regular readers because it’s about how to kill a user session. This is a skill worth learning, but really only applies to computers that have multiple people logged in at one time. If that’s describing you and your needs, this may be an article worth reading.

Of course, if that’s not something you do, you can still learn from this. It’s not all that complicated and is easy enough to follow. So, feel free to learn something – even if it isn’t something you’re likely to ever need.

There are times when you may have someone logged in and you want to log them out. For example, let’s say you’re getting ready to fire someone. You’re going to want to delete their account, make sure they’re logged out of their account, and then take them to HR where you can file paperwork and escort them (and their property) off the site.

You might also want to do stuff like log people out so that you can perform updates on the server. There are all sorts of reasons why you might want to kill a user session. Your reasons are your own. I’ll simply be showing you the tools.

Kill A User Session:

You’ll need an open terminal and to be connected to the computer you want to control. If you’re doing this, I’ll assume you’re aware of how to do those things. If you’re doing this on your own computer, you can usually press CTRL + ALT + T and your default terminal should open.

Once you’re connected (or have your own terminal) you can find the logged-in users with the following command:

Actually, you can just use this command:

The results are the same. So, either works.

You can now see the output which will show you every logged-in user on that device. Next, you’ll kill a user session with the following command:

If you wanted to use the kill command, you could find the associated processes (the PID) but there’s no reason to do so when you can just kill a user session with the username.

Closure:

There you go. I figured I’d do a nice, short, and easy article. It’s not very complicated and it’s not something many of you will need. However, if you’re managing a system with multiple people logged in, this is a very useful tool to have. You never know when someone’s going to come into your office and ask you to kill a user session. Well, now you know how…

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Change Your Home Directory

In today’s article you’re going to learn that it’s possible to change your home directory. Why? Because Ol’ David is in a bit of a rush to get this out on time. I can’t miss my publication deadline! So far, there has been an article every other day. Gotta keep up the schedule.

Yesterday was an extremely frustrating day. People managed to waste my entire afternoon. The only consolation I got was that I drove home really quickly, in a very spirited manner. That was not enough consolation. So, I just drank a couple of delicious beers (Sierra Nevada Pale Ale) and went to sleep.

I expected to get up early and write the article. I did wake up early, but I fell back to sleep. My body wanted to catch up on some missed sleep and it did. Which means I’ve got like an hour to write this article.

(I don’t think there has ever been a more ‘bloggy’ post than this one! It’s horrible and I’ll hopefully never do it again.)

When I first planned this article, I planned on showing you how to change your home directory with a new user. It was going to be fairly long and needlessly complicated. So, instead, I’m just going to tell you how to do it. You can learn how to create a new user.

So then, let’s get onto the meat of this…

Change Your Home Directory:

There are all sorts of reasons why you might want to change your home directory. Maybe you don’t want people being able to easily spot it by traversing your directory tree? You might want to move it to a different partition that has more space? Who knows?

But, this isn’t something you want to do willy-nilly. See, a whole lot of things depend on your home directory and your home directory probably contains a lot of stuff. So, after you’ve changed your home directory you’re probably going to need to move a lot of stuff around. That’s why it’s best to do this with a new user. If you want to practice this, I’d say do it to a new user. There’s a link in the preamble to learn how to create a new user.

The command is remarkably simple. Just open up your terminal and run:

So, if I wanted to move my home to /foo/bar, the command would look like:

You don’t have to specify /home/kgiii – even though that’s the full directory path. The -d command knows that we’re generally talking about the home directory. If you’ve already moved your home directory, and it is outside of the /home directory, you’re probably gonna have to specify that. I don’t actually know, I’ve never tried that.

This isn’t something I’d undertake lightly. I’d really only recommend this on a new user OR if there are some very specific circumstances. You might do this if you’ve filled up your disk space, added a new disk, and want to move your home directory to the new disk so that you don’t have to muck about with changing partitions or anything. Even then, it’s a bad solution – but probably one of the best solutions you have available.

Closure:

Consider this an article that’s for a very special set of circumstances. It’s for when someone on a forum has run out of disk space and wants a way out without any changes to partitioning and doesn’t want to reinstall. This isn’t something you probably need to go playing around with, but you can. I ain’t stopping you. The potential to make a mess of this is pretty strong.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Let’s Take A Look At Logged In Users

Today is a good day to learn how to take a look at logged in users. The vast majority of my readers are desktop users, so you can mostly skip this article. On the other hand, when you take a look at logged in users, you might find users you didn’t know were logged in and discover a problem like unknown users.

Yeah, most of you – including me at the moment (which makes it difficult to do things like take useful screenshots) are using Linux (mostly) as a single user. You have a user and you login to that user account when you start your system up.

While you do have other system-configured users, you don’t generally login as those users. As such, you probably spend very little time thinking about the users you have. Those system users aren’t generally logged in but are there for permissions purposes, so they’re out of mind for most of us.

Well, for the rest of you, you can use this article to learn how look logged in users – even getting a glimpse at what they’re doing. I mentioned some difficulty in taking screenshots, so I’ll provide you with just one. Cherish it, as it’s the only one you’re getting!

Here it is:

looking at other users
See? I’ll reference some of this below, in the article itself. I might as well…

Have A Look At Logged In Users:

This article requires an open terminal, like many other articles on this site. If you don’t know how to open the terminal, you can do so with your keyboard – just press CTRL + ALT + T and your default terminal should open.

As you can see from the image above you can see all the logged in users with the first command. The following command will list them:

You’ll see the same thing, with a bit more information, when you use the following command:

Now, in the image above, you can see where I used it once and then ran it again. What you don’t see is that, in between those two commands, I opened up another TTY and logged in again as ‘kgiii’. If you want to replicate that, just press CTRL + ALT, then F3 to F6, and login at the prompt with any user(s) you happen to have.

Finally, you can get a look at what they’re doing – like one has a desktop session open and two of those login instances just have bash sessions open in TTY sessions. To do that,  you just use:

That should be easy enough for you to remember! By the way, if you did login as an additional TTY instance, run ‘users‘ again and you’ll see the output for that command has changed accordingly. The command’s output will may also give you a good idea about how long the system has been up and what the system resources are like.

Closure:

There you have it. You have learned how to have a look at logged in users so that you can have an idea of what’s going on with your system. If you spot a user you don’t recognize, that might be indicative of a problem. If you spot a user you don’t recognize, you’ll need to do some more investigating. By the way, if you have ‘finger’ installed you can always run ‘finger <username>‘.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

How To: Create A New User

Today’s article is a nice and easy one, where you’ll learn how to create a new user. It’s a skill everyone should have and it’s really not all that difficult. It’s a pretty basic skill, after all. Either way, it shouldn’t be all that long, nor all that difficult.

In fact, I’ve previously covered some of this. Oddly, I’ve covered the more difficult stuff first. I’ve covered how to create a new user without a /home directory. I’ve also covered create a new user with sudo privileges. Oddly, I’ve never covered how to just plain create a new user. So, that’s what this article will explain.

The tool we’ll be using in this article is one you’ve used before, assuming you’ve been following the site. We’ll be using ‘adduser’ which the man page helpfully describes as:

adduser, addgroup – add a user or group to the system

As a tool, it does what it says on the tin. You can see that it’s also covering the ‘addgroup’ command. We won’t be covering that today, but it’s probably pretty obvious what it does. Hint: It is used to add groups! 

Alas, we’ll just be using the ‘adduser’ bit, in this pretty simple article to follow. Anyhow, you never know when you’ll want to create a new user and Linux is very much a multi-user operating system – even if you don’t realize it. Between users and groups, you can do some pretty fancy stuff with permissions.

Create A New User:

This article requires an open terminal, like oh so many do. To crack open a terminal, just press CTRL + ALT + T and your default terminal should open. See? It’s magic!

Now, with your terminal open, you can create a new user with:

Next, you’ll be asked for a password. Don’t be fooled, they want your root/sudo password and not the intended password for the new user. That will come later, after the user is created. The application will tell you what it’s doing, such as creating the new user, creating the new user’s home directory, and copying the default files to the new user’s home directory.

After it’s done with that, it’ll ask you for some finishing information. You’ll be asked to type the password. That’s when you enter the password for the new user. You’ll be asked to confirm it to make sure you typed it properly. It’ll then confirm that it has set the password, ‘adduser’ is helpful like that.

At this point,  you can opt to include more information. None of this is required information and you can leave the fields blank. But, if you want, you can fill the fields for things like the new user’s real name, their phone number(s), and even what room they are in.

Given that most of my readers are home users, you’re probably not going to need to add that information. Either way, when you’re done with that you will need to confirm the information. This is obvious, but you enter Y to confirm the data, or N to go back and edit something. When you finish that, you will have a new user account that you can use immediately.

Closure:

There you have it. You now have a new article. This one will have taught you how to create a new user. As I’ve mentioned, Linux is a multi-user operating system by design and, as such, you’ll eventually need to know how to create a new user. And… When that happens… You’ll either remember – or you’ll be able to search linux-tips.us for the answer! We’ve got well over 200 articles, so we’ve covered a lot of subjects.

Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.

Linux Tips
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.