Python exception and permission denied exception while trying to run "az login" on ubuntu

7/7/2018

I am new in Linux/k8s and trying to run az CLI on Ubuntu VM.

After following all instructions to install CLI and kubectl as following:

- Install az CLI:
    ○ AZ_REPO=$(lsb_release -cs) echo "deb [arch=amd64] 
       https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | sudo 
       tee /etc/apt/sources.list.d/azure-cli.list
    ○ curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt key add -
    ○ sudo apt-get install apt-transport-https
      sudo apt-get update && sudo apt-get install azure-cli
- Install kubectl:
    ○ sudo apt-get update && sudo apt-get install -y apt-transport-https
      curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo 
      apt-key add -
      sudo touch /etc/apt/sources.list.d/kubernetes.list 
      echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee 
       -a /etc/apt/sources.list.d/kubernetes.list
      sudo apt-get update
      sudo apt-get install -y kubectl

I got the following error message if I try to run az login as root:

"Port '8400' is taken. Trying with the next one Note, we have launched a browser for you to login. For old experience with device code, use "az login --use-device-code" Running Firefox as root in a regular user's session is not supported. "

Also, if I try to run it using my non-root account, it gives me the following trace erros:

 Traceback (most recent call last):
  File "/opt/az/lib/python3.6/configparser.py", line 1138, in _unify_values
  sectiondict = self._sections[section]
KeyError: 'cloud'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/cloud.py", line 234, 
in get_active_cloud_name
return cli_ctx.config.config_parser.get('cloud', 'name')
File "/opt/az/lib/python3.6/configparser.py", line 781, in get
d = self._unify_values(section, vars)
File "/opt/az/lib/python3.6/configparser.py", line 1141, in _unify_values
  raise NoSectionError(section)
configparser.NoSectionError: No section: 'cloud'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/opt/az/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/opt/az/lib/python3.6/runpy.py", line 85, in _run_code
  exec(code, run_globals)
File "/opt/az/lib/python3.6/site-packages/azure/cli/__main__.py", line 32, in 
  <module>
  az_cli = get_default_cli()
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 
  493, in get_default_cli
  help_cls=AzCliHelp)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 
  53, in __init__
  self.cloud = get_active_cloud(self)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/cloud.py", line 299, 
  in get_active_cloud
  return get_cloud(cli_ctx, get_active_cloud_name(cli_ctx))
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/cloud.py", line 236, 
  in get_active_cloud_name
  _set_active_cloud(cli_ctx, AZURE_PUBLIC_CLOUD.name)
File "/opt/az/lib/python3.6/site-packages/azure/cli/core/cloud.py", line 229, 
  in _set_active_cloud
  cli_ctx.config.set_value('cloud', 'name', cloud_name)
File "/opt/az/lib/python3.6/site-packages/knack/config.py", line 91, in 
  set_value
  self.set(config)
File "/opt/az/lib/python3.6/site-packages/knack/config.py", line 78, in set
  with open(self.config_path, 'w') as configfile:

PermissionError: [Errno 13] Permission denied: '/home/<useraccount>/.azure/config'

Please help.

Thanks

-- Helay
azure
containers
kubernetes
ubuntu
virtual-machine

1 Answer

7/7/2018

It clearly says you need to run az login --use-device-code. Is your ubuntu is headless and incapable of running browsers? If it is - use the method suggested if not - check system logs, why it cannot start browser (or at least thinks so)

Anyway, you can grant yourself permissions to the file /home/<useraccount>/.azure/config and try to run without root

-- 4c74356b41
Source: StackOverflow