Computer

Linux, how to delete a user

Use multiple accounts on one operating system Linux (but the discussion obviously also applies to Windows e MacOS) means allowing more people to work on the same PC, without the risk of delete or modify inadvertently other people’s files.

They correspond to each account documents, software e user-defined settings who accesses it and everything is protected by a password which, generally, is known only to the owner of this “space”.

Clearly, have too many accounts (especially if unused) is not good for the PC and every now and then it is good to eliminate the “useless” ones to make some space to perhaps be allocated to active users. Likewise, in the case of company PCs, when one of the employees no longer needs their account, deleting it can be a way to recover space to assign to someone else.

Generally this task affects to the system administrator, therefore the following instructions necessarily require administrator privileges. Let’s see how to do it.

  • 1. Check access before deletion

    Before proceeding with deleting an account you need to check if the user is logged in o meno.

    Starting with a check like this is never a given and, above all, it allows you to give a sort of “warning” about the fate that will befall that profile, giving the user in question time to save their work or possibly make a backup.

    To do this you can use the Who commandwhich shows the active sessions on that PCall references on the last access and, in the case of an active user, what operations it is performing.

    By entering the command -u username you can see them running processes and all relevant information including system resources used or any other suspicious activity which, of course, the system administrator can stop at any timekicking the user in question out of the account.

    Two clarifications: the first is that this operation can also be done just to check what a given account is doing. The second is that before attempting this path in view of a future elimination it is good freeze the account e change passwordso that the owner can no longer access it.

    At this point, before proceeding with the removal it may also be useful stop all processes running.

    To do this you can open the terminal and use the sudo command pkill -KILL -u nome utente.

  • 2. Remove scheduled jobs

    Before delete one or more users on Linux it is always better to check if there are gods planned processes for the account in question.

    The function is called cron jobs and represents a certain command that is activated at specific times or intervals.

    To check for the presence of cron jobs you can use the command sudo ls -lh /var/spool/cron/crontabs/username to be inserted, obviously, always in the terminal.

    If anything is identified, it means that the user being removed had scheduled processes which, of course, can be removed by the administrator.

    To do this you can type the command sudo crontab -r -u username and eliminate any such operation.

  • 3. Remove print jobs

    Likewise the user who is about to be removed could have some pending print jobs; this does not imply anything for deleting the account but is still useful for verifying all the operations carried out with that given profile and having a complete picture of the whole situation.

    To remove them, just type the command in the terminal lprm – The user name and proceed to remove all documents ready to be printed.

  • 4. Archive the user directory

    If the decision has been made to delete a user from Linuxit is not necessarily necessary to lose all the content of his profile.

    It is possible, in fact, archive the entire directory in order to make it accessible (always with the administrator password) at a later time.

    There are many options available and, for example, it is possible create a file archiverename it, compress it and send it to some other directory for long-term storage.

    To do this you can use the command sudo tar cfjv username.tar.bz /home/username and then the command ls -lh username.tar.bz to insert it into an archive to copy elsewhere.

  • 5. How to delete one or more users from Linux

    After closing all running processes and backing up the files of a particular account, we can see how delete one or more users from Linux.

    In this case, the command to use depends on the Linux distribution you are using. For them Linux distributions based on Debianthe command is deluserwhile for all the others it can be used userdel.

    Both commands perform the same function and on Ubuntufor example, both can be used.

    After entering the command deluser username or userdel username, that’s it and there will be no trace of the account in question left on your computer.

    Of course this operation will erase all traces of that account Linux on your PC and there is no way to restore what is deleted, unless you have backed up your data as explained in the previous paragraphs.

    For this reason it is always good to save the contents of any account and, of course, be aware of the fact that deletion is an irreversible process.

    To know more: Linux, features and distributions

Leave a Reply

Your email address will not be published. Required fields are marked *