I used the command pkill
as root on my vps ubuntu, and I got kicked out of the server and can't access it.
This is what I wrote inside the terminal:
pkill h
h is my user in ubuntu
What is the solution?
I used the command pkill
as root on my vps ubuntu, and I got kicked out of the server and can't access it.
This is what I wrote inside the terminal:
pkill h
h is my user in ubuntu
What is the solution?
If you want to kill all processes belonging to a particular user, use
pkill -U user .
The .
at the end matches any process name, and -U user
restricts the operation to processes belonging to the user called user
.
To see what processes would be affected by a pkill
command, you could replace the pkill
command itself with pgrep
, and then possibly add -l
to get "long output" (the process names would be displayed too).
pgrep -l h
The above commend should show you all commands on the system that contains the character h
in its name, while the command below would show you all commands belonging to the user called user
:
pgrep -l -U user .
You told us,
This is what I wrote inside the terminal:
pkill h
Furthermore, you did this as root
. What happened here is that you killed all processes containing h
in the name. This included the master sshd
, which controls inbound ssh
requests, as well as all its children that mediate existing connections.
Unless you can log on to the non-graphical console and restart it yourself, you're going to need to arrange for your system to be forcibly rebooted.
I would strongly recommend that you get into the habit of checking the documentation for command with which you're unfamiliar. Here, man pkill
shows as its very first example a method for selecting only processes owned by a particular user. Applying the example to your situation,
pkill -u h # user "h"
Better still, use pgrep
first to check you've matched the correct set of processes:
pgrep -a -u h # -a shows "all" the command line, for user "h"
Or send signal 0, which has no action:
pkill -0 -e -u h # Signal zero, "echo" affected processes, for user "h"
Notice that the username must be an exact match, but a process name is a partial match. (This is why h
in your original command matched sshd
.)
man ill
on your terminal for more info. – Pablo A Nov 08 '21 at 21:02