Article directory
1. How to delete the virtual environment in the remote server?
Delete the conda virtual environment under Linux system:
# 删除虚拟环境
conda remove -n your_env_name(虚拟环境名称) --all
# 删除虚拟环境中的包
conda remove --name $your_env_name $package_name(包名)
I wanted to try to delete a certain virtual environment and found:
(wzk_base) wangzhenkuan@3090:~$ conda remove -n xhl_base --all
Remove all packages in environment /home/miniconda3/envs/xhl_base:
## Package Plan ##
environment location: /home/miniconda3/envs/xhl_base
The following packages will be REMOVED:
_libgcc_mutex-0.1-main
blas-1.0-mkl
brotlipy-0.7.0-py38h27cfd23_1003
ca-certificates-2020.12.8-h06a4308_0
certifi-2020.12.5-py38h06a4308_0
cffi-1.14.3-py38h261ae71_2
chardet-3.0.4-py38h06a4308_1003
conda-package-handling-1.7.2-py38h03888b9_0
cryptography-3.2.1-py38h3c74f83_1
idna-2.10-py_0
intel-openmp-2020.2-254
ld_impl_linux-64-2.33.1-h53a641e_7
libedit-3.1.20191231-h14c3975_1
libffi-3.3-he6710b0_2
libgcc-ng-9.1.0-hdf63c60_0
libstdcxx-ng-9.1.0-hdf63c60_0
mkl-2020.2-256
mkl-service-2.3.0-py38he904b0f_0
mkl_fft-1.2.0-py38h23d657b_0
mkl_random-1.1.1-py38h0573a6f_0
ncurses-6.2-he6710b0_1
numpy-1.19.2-py38h54aff64_0
numpy-base-1.19.2-py38hfa32c7d_0
openssl-1.1.1i-h27cfd23_0
pip-20.2.4-py38h06a4308_0
pycosat-0.6.3-py38h7b6447c_1
pycparser-2.20-py_2
pyopenssl-19.1.0-pyhd3eb1b0_1
pysocks-1.7.1-py38h06a4308_0
python-3.8.5-h7579374_1
pyyaml-5.3.1-py38h7b6447c_1
readline-8.0-h7b6447c_0
requests-2.24.0-py_0
ruamel_yaml-0.15.87-py38h7b6447c_1
setuptools-50.3.1-py38h06a4308_1
six-1.15.0-py38h06a4308_0
sqlite-3.33.0-h62c20be_0
tk-8.6.10-hbc83047_0
tqdm-4.51.0-pyhd3eb1b0_0
urllib3-1.25.11-py_0
wheel-0.35.1-pyhd3eb1b0_0
xz-5.2.5-h7b6447c_0
yaml-0.2.5-h7b6447c_0
zlib-1.2.11-h7b6447c_3
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: failed
EnvironmentNotWritableError: The current user does not have write permissions to the target environment.
environment location: /home/miniconda3/envs/xhl_base
uid: 1015
gid: 1234
But the current user does not have sufficient permissions to write to the environment. This is usually caused by some of the following situations:
Missing permissions : Your user does not have sufficient permissions to write in the target environment. This may be because you are not running the operation as administrator, or you are trying to modify a restricted environment.
Environment location issue : Maybe your conda environment is located somewhere that requires special permissions. Make sure you have permission to write to the location.
The environment is corrupted : Sometimes, the environment may be corrupted or unwritable, preventing operations. You can try creating a new conda environment and verify if the same issue exists.
The solution was to give myself some permissions:
sudo chmod 777 /home/miniconda3/ -R
By running the following command, we set recursive permissions to 777 for the /home/miniconda3/ directory and all its subdirectories and files.
This will give all users full read, write, and execute permissions to the directory. Note that using permissions 777 may pose a security risk because any user can make changes to or delete files in the directory. Use this permission with caution and only when necessary.
The virtual environment was successfully deleted!
2. How to delete users from the remote server?
First we check which users are in the server:
cat /etc/passwd
We try to remove:
userdel xuhuiling
Code error:
userdel: Permission denied.
userdel:无法锁定 /etc/passwd,请稍后再试。
In a Linux system, to delete a user account, you usually need a super user (root authority) or the authority to manage user accounts to perform this operation. In our case, I got a "Permission denied" error when executing the userdel command, this was because my current user did not have sufficient permissions to delete the user account.
To delete a user account, follow these steps:
- Use the sudo command: If you have sudo permissions (i.e. you can run commands as an administrator), you can use the sudo userdel command to delete the user. For example:
sudo userdel xuhuiling
You will then be asked to enter your administrator password to confirm the deletion.
- Use root permissions: If you have root user access permissions, you can log in directly as root and then execute the userdel command without using sudo. Example:
su - # 切换到root用户
userdel xuhuiling # 删除用户
Please proceed with caution as deleting a user permanently deletes their user folders and associated data.
We choose to use:
sudo userdel xuhuiling
But still got an error:
userdel: user xuhuiling is currently used by process 2215850
The error message indicates that user xuhuiling is currently being used by one or more processes, so the user cannot be deleted immediately. Before deleting a user, we need to ensure that there are no running processes or services using the user. Here are steps you can take:
- Find and stop related processes: Use the ps or top command to find processes using the xuhuiling user. Then use the kill command to stop these processes. For example:
ps aux | grep xuhuiling
It looks like there are two sessions using user xuhuiling. Both sessions appear to be started via the su command, which means they are run as user xuhuiling. Before deleting the user, we need to ensure that both sessions have exited.
This way you can delete it smoothly!
3. How to delete a folder?
sudo rm -r /home/xvhuiling
This will delete the /home/xvhuiling directory and all its subdirectories and files. Use the rm command with caution because the deletion operation is irreversible and will permanently delete all data in the directory.