1

I am currently writing a little script that should automatically be executed as soon as certain users log onto the server. They are then allowed to add a user and should be logged out afterward instantly so that they dont meddle with my server. To achieve this i wrote the following function:

def logout_fkt():
logout = input("Do you wish to log out ? (yes / no): ")  # Maybe the user wants to add another user
if logout == 'no':
    add_user()
else:
    os.system("logout")

The servers runs on the ubuntu20.04 so the command logout definitly exists. But somehow if i execute it via the os.system() i get the following error message: sh: 1: logout: not found which would indicate that the command does not exist, which of course is not true. I am lost.

1 Answers1

0

The logout command is a built-in command in Bash and not something you can call from outside a shell.

If you want users to SSH to your box and only run your program you can set it as their default shell, or only allow that program to be run.

On both of those cases the SSH session will be terminated when your program exists and no shell will be available to the user.

Be aware though, that this is fraught with massive security concerns.

Raniz
  • 10,882
  • 1
  • 32
  • 64