本文档翻译自:https://docs.conan.io/en/latest/reference/commands/misc/user.html

  1. $ conan user [-h] [-c] [-p [PASSWORD]] [-r REMOTE] [-j JSON] [-s] [name]

使用用户/密码对远程进行身份验证,缓存auth令牌。
有助于避免以后要求用户和密码。 例如 在您上传包裹时。 每个遥控器可以有一个用户。 更改用户或引入密码仅是在远程软件包中执行更改所必需的。

  1. positional arguments:
  2. name Username you want to use. If no name is provided it
  3. will show the current user
  4. optional arguments:
  5. -h, --help show this help message and exit
  6. -c, --clean Remove user and tokens for all remotes
  7. -p [PASSWORD], --password [PASSWORD]
  8. User password. Use double quotes if password with
  9. spacing, and escape quotes if existing. If empty, the
  10. password is requested interactively (not exposed)
  11. -r REMOTE, --remote REMOTE
  12. Use the specified remote server
  13. -j JSON, --json JSON json file path where the user list will be written to
  14. -s, --skip-auth Skips the authentication with the server if there are
  15. local stored credentials. It doesn't check if the
  16. current credentials are valid or not

Examples:
列出每个远程服务器的所使用的用户:

  1. $ conan user
  2. Current user of remote 'conan-center' set to: 'danimtb' [Authenticated]
  3. Current user of remote 'bincrafters' set to: 'None' (anonymous)
  4. Current user of remote 'upload_repo' set to: 'danimtb' [Authenticated]
  5. Current user of remote 'conan-community' set to: 'danimtb' [Authenticated]
  6. Current user of remote 'the_remote' set to: 'None' (anonymous)

将bar远程用户更改为foo:

  1. $ conan user foo -r bar
  2. Changed user of remote 'bar' from 'None' (anonymous) to 'foo'

将bar远程用户更改为foo,以对远程进行身份验证并在本地存储用户和身份验证令牌,因此以后的上传无需输入凭据:

  1. $ conan user foo -r bar -p mypassword

仅当我们没有本地存储的凭据时,才根据远程服务器进行身份验证。 它不会检查凭据是否有效:

  1. $ conan user foo -r bar -p mypassword --skip-auth

清除所有本地用户和令牌:

  1. $ conan user --clean

将bar远程用户更改为foo,要求用户密码针对远程进行身份验证,并在本地存储用户和身份验证令牌,因此以后的上传无需输入凭据:

  1. $ conan user foo -r bar -p
  2. Please enter a password for "foo" account:
  3. Change 'bar' user from None (anonymous) to foo

:::info Note
密码不会随时存储在客户端计算机中。 Conan使用JWT,因此它获得令牌(服务器可过期)以根据远程凭据检查密码。 如果密码正确,将获取身份验证令牌,该令牌是本地缓存的信息。 对于随后与遥控器的任何交互,Conan客户端将仅使用该JWT令牌。 :::

使用环境变量

使用CONAN_LOGIN_USERNAME和CONAN_PASSWORD环境变量可以在环境中定义用户和密码。 如果定义了这些环境变量,则无论何时要求用户或密码,都不需要用户输入。 用户和密码的值将自动从环境变量中获取,而无需任何交互式输入。
这也适用于conan用户命令,如果您想在某些脚本中强制进行身份验证,而无需以纯文本形式输入密码,则可以执行以下操作:

  1. $ conan user --clean # remove previous auth tokens
  2. $ export CONAN_PASSWORD=mypassword
  3. $ conan user mysyusername -p -r=myremote
  4. Please enter a password for "mysusername" account: Got password '******' from environment
  5. Changed user of remote 'myremote' from 'None' (anonymous) to 'mysusername'
  6. $ conan upload zlib* -r=myremote --all --confirm

在此示例中,如果未定义CONAN_PASSWORD,则柯南用户mysyusername -p -r = myremote将以交互方式请求密码。
可以定义环境变量CONAN_NON_INTERACTIVE(或conan.conf中的general.non_interactive)以确保如果需要用户输入将引发错误,以避免CI构建中的停顿。
请注意,在任何情况下,定义CONAN_LOGIN_USERNAME和/或CONAN_PASSWORD都不会对服务器执行身份验证请求。 仅当服务器请求凭据时(或完成显式的cona用户-p时),它们才会用作备用源,而不是交互式用户输入。 这意味着对于像Artifactory这样的允许启用“隐藏未授权资源的存在”模式的服务器,有必要在从服务器下载或上传任何内容之前显式调用conan用户-p,否则,Artifactory将返回404错误而不是请求身份验证 。