linux 新建用户并将anaconda复制过来

技术 · 2023-11-13 · 477 人浏览

我现在在服务器新建了一个用户user1,然后现在我需要将原用户下的anaconda3复制到新用户下,使用root用户操作:

要将原用户下的 Anaconda 安装复制到服务器上新建的 user1 用户,并使用 root 用户执行操作,您可以遵循以下步骤:

  1. 登录为 root 用户:首先,您需要以 root 用户身份登录到服务器。
  2. 复制 Anaconda 目录:使用 cp 命令复制原用户的 Anaconda 目录到 user1 的主目录。假设原 Anaconda 目录位于 /home/original_user/anaconda3,您可以执行:

    cp -R /home/original_user/anaconda3 /home/user1/

    这个命令会递归地(-R)复制整个 anaconda3 目录。

  3. 更改目录所有者:将新复制的 Anaconda 目录的所有权更改为 user1。这样 user1 就可以访问和修改这些文件了。

    chown -R user1:user1 /home/user1/anaconda3
  4. 更新 user1 的环境变量:需要确保 user1PATH 环境变量包括 Anaconda 的 bin 目录。您可以在 user1.bashrc.bash_profile 文件中添加以下行:

    export PATH="/home/user1/anaconda3/bin:$PATH"

    然后,作为 user1,重新加载 .bashrc 或重新登录以应用更改。

  5. 检查和测试:切换到 user1 用户(使用 su - user1),然后尝试运行一些基本的 Conda 命令,如 conda list,来检查安装是否成功。
  6. 可选 - 重新初始化 Conda:在 user1 的会话中,您可以运行 conda init 来设置正确的 shell 钩子。

问题1:

Traceback (most recent call last):
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/exception_handler.py", line 17, in __call__
    return func(*args, **kwargs)
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/cli/main.py", line 54, in main_subshell
    parser = generate_parser(add_help=True)
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/cli/conda_argparse.py", line 115, in generate_parser
    configure_parser_create(sub_parsers)
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/cli/conda_argparse.py", line 767, in configure_parser_create
    add_parser_solver(solver_mode_options)
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/cli/conda_argparse.py", line 1975, in add_parser_solver    solver.name for solver in context.plugin_manager.get_hook_results("solvers")
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/base/context.py", line 492, in plugin_manager
    from ..plugins.manager import get_plugin_manager
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/plugins/__init__.py", line 28, in <module>
    from .hookspec import hookimpl  # noqa: F401
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/plugins/hookspec.py", line 16, in <module>
    from .types import (
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/plugins/types.py", line 15, in <module>
    from ..core.solve import Solver
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/core/solve.py", line 42, in <module>
    from .index import _supplement_index_with_system, get_reduced_index
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/core/index.py", line 25, in <module>
    from .subdir_data import SubdirData, make_feature_record
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/core/subdir_data.py", line 54, in <module>
    from ..trust.signature_verification import signature_verification
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/trust/signature_verification.py", line 13, in <module>
    from conda_content_trust.authentication import verify_delegation, verify_root
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda_content_trust/authentication.py", line 34, in <module>
    from .common import (
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda_content_trust/common.py", line 66, in <module>
    import cryptography.hazmat.backends.openssl.ed25519
  File "/home/user1/anaconda3/lib/python3.10/site-packages/cryptography/hazmat/backends/openssl/__init__.py", line 7, in <module>
    from cryptography.hazmat.backends.openssl.backend import backend
  File "/home/user1/anaconda3/lib/python3.10/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 27, in <module>
    from cryptography.hazmat.bindings.openssl import binding
  File "/home/user1/anaconda3/lib/python3.10/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 167, in <module>
    Binding.init_static_locks()
  File "/home/user1/anaconda3/lib/python3.10/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 134, in init_static_locks
    cls._ensure_ffi_initialized()
  File "/home/user1/anaconda3/lib/python3.10/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 123, in _ensure_ffi_initialized
    _legacy_provider_error(cls._legacy_provider_loaded)
  File "/home/user1/anaconda3/lib/python3.10/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 43, in _legacy_provider_error
    raise RuntimeError(
RuntimeError: OpenSSL 3.0's legacy provider failed to load. This is a fatal error by default, but cryptography supports running without legacy algorithms by setting the environment variable CRYPTOGRAPHY_OPENSSL_NO_LEGACY. If you did not expect this error, you have likely made a mistake with your OpenSSL configuration.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user1/anaconda3/bin/conda", line 13, in <module>
    sys.exit(main())
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/cli/main.py", line 109, in main
    return conda_exception_handler(main, *args, **kwargs)
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/exception_handler.py", line 389, in conda_exception_handler
    return_value = exception_handler(func, *args, **kwargs)
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/exception_handler.py", line 20, in __call__
    return self.handle_exception(exc_val, exc_tb)
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/exception_handler.py", line 76, in handle_exception
    return self.handle_unexpected_exception(exc_val, exc_tb)
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/exception_handler.py", line 89, in handle_unexpected_exception
    self.print_unexpected_error_report(error_report)
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/exception_handler.py", line 160, in print_unexpected_error_report
    from .cli.main_info import get_env_vars_str, get_main_info_str
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/cli/main_info.py", line 19, in <module>
    from ..core.index import _supplement_index_with_system
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/core/index.py", line 25, in <module>
    from .subdir_data import SubdirData, make_feature_record
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/core/subdir_data.py", line 54, in <module>
    from ..trust.signature_verification import signature_verification
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda/trust/signature_verification.py", line 13, in <module>
    from conda_content_trust.authentication import verify_delegation, verify_root
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda_content_trust/authentication.py", line 34, in <module>
    from .common import (
  File "/home/user1/anaconda3/lib/python3.10/site-packages/conda_content_trust/common.py", line 66, in <module>
    import cryptography.hazmat.backends.openssl.ed25519
  File "/home/user1/anaconda3/lib/python3.10/site-packages/cryptography/hazmat/backends/openssl/__init__.py", line 7, in <module>
    from cryptography.hazmat.backends.openssl.backend import backend
  File "/home/user1/anaconda3/lib/python3.10/site-packages/cryptography/hazmat/backends/openssl/backend.py", line 27, in <module>
    from cryptography.hazmat.bindings.openssl import binding
  File "/home/user1/anaconda3/lib/python3.10/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 167, in <module>
    Binding.init_static_locks()
  File "/home/user1/anaconda3/lib/python3.10/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 134, in init_static_locks
    cls._ensure_ffi_initialized()
  File "/home/user1/anaconda3/lib/python3.10/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 123, in _ensure_ffi_initialized
    _legacy_provider_error(cls._legacy_provider_loaded)
  File "/home/user1/anaconda3/lib/python3.10/site-packages/cryptography/hazmat/bindings/openssl/binding.py", line 43, in _legacy_provider_error
    raise RuntimeError(
RuntimeError: OpenSSL 3.0's legacy provider failed to load. This is a fatal error by default, but cryptography supports running without legacy algorithms by setting the environment variable CRYPTOGRAPHY_OPENSSL_NO_LEGACY. If you did not expect this error, you have likely made a mistake with your OpenSSL configuration.

遇到的问题是与 Anaconda 中的 OpenSSL 配置相关的。错误提示表明 OpenSSL 3.0 的旧版提供程序加载失败,这通常是由于环境配置不当造成的。要解决这个问题,您可以尝试以下几个步骤:

设置环境变量:根据错误消息的建议,您可以尝试设置一个环境变量来允许不使用旧版算法。这可以通过在 user1.bashrc.bash_profile 中添加以下行来实现:

export CRYPTOGRAPHY_OPENSSL_NO_LEGACY=1

添加后,执行 source ~/.bashrc 或重新登录以应用更改。

问题2:

无法运行命令 'jupyter': 权限不够

解决方法

使用 sed 批量替换路径:您可以使用 sed 命令来批量更新文件中的路径。例如,如果您想将所有文件中的 /old/path 替换为 /new/path,可以在 Anaconda 目录中运行如下命令:

find /new/path/anaconda3 -type f -exec sed -i 's|/old/path|/new/path|g' {} +

这将查找 Anaconda 目录下的所有文件,并用新路径替换旧路径。请注意,这可能是一个风险较高的操作,因为它会修改大量文件,所以建议在执行之前备份您的 Anaconda 目录。

重新配置jupyter lab

然后需要重新配置jupyter的所有配置,包括生成密码。

  1. jupyter lab 的密码设定
ipython

执行完成后

from jupyter_server.auth import passwd; passwd()

输入想要的密码, 会转换成加密之后的密码。 保存到一个地方

  1. 在terminal 里执行
jupyter-lab --generate-config

会生成jupyter 的配置文件

用vim 打开修改几个地方

 vi ~/.jupyter/jupyter_lab_config.py

修改以下地方

c.ServerApp.allow_remote_access = True
c.ServerApp.ip = '0.0.0.0'
c.ServerApp.open_browser = False  
c.ServerApp.password = '上面保存的密码'
c.ServerApp.port = 9999
  1. 启动jupyterlab就可以愉快的做实验了
  2. 后台挂起命令
nohup jupyter lab &
Linux jupyter Anaconda
Theme Jasmine by Kent Liao