azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

"UNPROTECTED PRIVATE KEY FILE" error when using `az ssh vm`

Open lb-cyway-one opened this issue 3 years ago • 49 comments

Describe the bug

When trying to connect to a Linux VM in Azure from a AAD-joined Windows Server 2022, I'm facing a "UNPROTECTED PRIVATE KEY FILE" error.

I have followed the following documentation for this setup : https://learn.microsoft.com/en-us/azure/active-directory/devices/howto-vm-sign-in-azure-ad-linux

I've tried to change the permission of the parent folder (C:\Users\user\AppData\Local\Temp) but the problem persists.

Related command

az ssh vm --ip 192.168.1.5

Errors

C:\Users\user>az ssh vm --ip 192.168.1.5 OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions for 'C:\Users\user\AppData\Local\Temp\2\aadsshcertxhknyen8\id_rsa.pub-aadcert.pub' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. Load key "C:\Users\user\AppData\Local\Temp\2\aadsshcertxhknyen8\id_rsa.pub-aadcert.pub": bad permissions [email protected]@192.168.1.5: Permission denied (publickey).

C:\Users\user>

Issue script & Debug output

C:\Users\user>az ssh vm --ip 192.168.1.5 --debug cli.knack.cli: Command arguments: ['ssh', 'vm', '--ip', '192.168.1.5', '--debug'] cli.knack.cli: init debug log: Enable color in terminal. Enable VT mode. cli.knack.cli: Event: Cli.PreExecute [] cli.knack.cli: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x017AB4A8>, <function OutputProducer.on_global_arguments at 0x018AB6E8>, <function CLIQuery.on_global_arguments at 0x019C8340>] cli.knack.cli: Event: CommandInvoker.OnPreCommandTableCreate [] cli.azure.cli.core: Modules found from index for 'ssh': ['azext_ssh'] cli.azure.cli.core: Loading command modules: cli.azure.cli.core: Name Load Time Groups Commands cli.azure.cli.core: Total (0) 0.000 0 0 cli.azure.cli.core: These extensions are not installed and will be skipped: ['azext_ai_examples', 'azext_next'] cli.azure.cli.core: Loading extensions: cli.azure.cli.core: Name Load Time Groups Commands Directory cli.azure.cli.core: ssh 0.482 1 4 C:\Users\user.azure\cliextensions\ssh cli.azure.cli.core: Total (1) 0.482 1 4 cli.azure.cli.core: Loaded 1 groups, 4 commands. cli.azure.cli.core: Found a match in the command table. cli.azure.cli.core: Raw command : ssh vm cli.azure.cli.core: Command table: ssh vm cli.knack.cli: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x03B6B4F0>] cli.azure.cli.core.azlogging: metadata file logging enabled - writing logs to 'C:\Users\user.azure\commands\2023-08-08.15-50-26.ssh_vm.3816.log'. az_command_data_logger: command args: ssh vm --ip {} --debug cli.knack.cli: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument..add_subscription_parameter at 0x03B93610>] cli.knack.cli: Event: CommandInvoker.OnPostArgumentLoad [] cli.knack.cli: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument..add_ids_arguments at 0x03BA4580>, <function register_cache_arguments..add_cache_arguments at 0x03BA4778>] cli.knack.cli: Event: CommandInvoker.OnCommandTableLoaded [] cli.knack.cli: Event: CommandInvoker.OnPreParseArgs [] cli.knack.cli: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x018AB730>, <function CLIQuery.handle_query_parameter at 0x019C8388>, <function register_ids_argument..parse_ids_arguments at 0x03BA4730>] az_command_data_logger: extension name: ssh az_command_data_logger: extension version: 2.0.1 cli.azure.cli.core.commands.client_factory: Getting management service client client_type=ComputeManagementClient cli.azure.cli.core.auth.persistence: build_persistence: location='C:\Users\user\.azure\msal_token_cache.bin', encrypt=True cli.azure.cli.core.auth.binary_cache: load: C:\Users\user.azure\msal_http_cache.bin urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None) msal.authority: openid_config = {'token_endpoint': 'https://login.microsoftonline.com//oauth2/v2.0/token', 'token_endpoint_auth_methods_supported': ['client_secret_post', 'private_key_jwt', 'client_secret_basic'], 'jwks_uri': 'https://login.microsoftonline.com//discovery/v2.0/keys', 'response_modes_supported': ['query', 'fragment', 'form_post'], 'subject_types_supported': ['pairwise'], 'id_token_signing_alg_values_supported': ['RS256'], 'response_types_supported': ['code', 'id_token', 'code id_token', 'id_token token'], 'scopes_supported': ['openid', 'profile', 'email', 'offline_access'], 'issuer': 'https://login.microsoftonline.com//v2.0', 'request_uri_parameter_supported': False, 'userinfo_endpoint': 'https://graph.microsoft.com/oidc/userinfo', 'authorization_endpoint': 'https://login.microsoftonline.com//oauth2/v2.0/authorize', 'device_authorization_endpoint': 'https://login.microsoftonline.com//oauth2/v2.0/devicecode', 'http_logout_supported': True, 'frontchannel_logout_supported': True, 'end_session_endpoint': 'https://login.microsoftonline.com//oauth2/v2.0/logout', 'claims_supported': ['sub', 'iss', 'cloud_instance_name', 'cloud_instance_host_name', 'cloud_graph_host_name', 'msgraph_host', 'aud', 'exp', 'iat', 'auth_time', 'acr', 'nonce', 'preferred_username', 'name', 'tid', 'ver', 'at_hash', 'c_hash', 'email'], 'kerberos_endpoint': 'https://login.microsoftonline.com//kerberos', 'tenant_region_scope': 'EU', 'cloud_instance_name': 'microsoftonline.com', 'cloud_graph_host_name': 'graph.windows.net', 'msgraph_host': 'graph.microsoft.com', 'rbac_url': 'https://pas.windows.net'} msal.application: Broker enabled? True cli.azext_ssh.ssh_utils: Platform architecture: 32bit cli.azext_ssh.ssh_utils: OS architecture: 64bit cli.azext_ssh.ssh_utils: System Root: C:\Windows cli.azext_ssh.ssh_utils: Attempting to run ssh-keygen from path C:\Windows\SysNative\openSSH\ssh-keygen.exe cli.azext_ssh.ssh_utils: Running ssh-keygen command C:\Windows\SysNative\openSSH\ssh-keygen.exe -f C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa -t rsa -q -N urllib3.util.retry: Converted retries value: 1 -> Retry(total=1, connect=None, read=None, redirect=None, status=None) msal.authority: openid_config = {'token_endpoint': 'https://login.microsoftonline.com//oauth2/v2.0/token', 'token_endpoint_auth_methods_supported': ['client_secret_post', 'private_key_jwt', 'client_secret_basic'], 'jwks_uri': 'https://login.microsoftonline.com//discovery/v2.0/keys', 'response_modes_supported': ['query', 'fragment', 'form_post'], 'subject_types_supported': ['pairwise'], 'id_token_signing_alg_values_supported': ['RS256'], 'response_types_supported': ['code', 'id_token', 'code id_token', 'id_token token'], 'scopes_supported': ['openid', 'profile', 'email', 'offline_access'], 'issuer': 'https://login.microsoftonline.com//v2.0', 'request_uri_parameter_supported': False, 'userinfo_endpoint': 'https://graph.microsoft.com/oidc/userinfo', 'authorization_endpoint': 'https://login.microsoftonline.com//oauth2/v2.0/authorize', 'device_authorization_endpoint': 'https://login.microsoftonline.com//oauth2/v2.0/devicecode', 'http_logout_supported': True, 'frontchannel_logout_supported': True, 'end_session_endpoint': 'https://login.microsoftonline.com//oauth2/v2.0/logout', 'claims_supported': ['sub', 'iss', 'cloud_instance_name', 'cloud_instance_host_name', 'cloud_graph_host_name', 'msgraph_host', 'aud', 'exp', 'iat', 'auth_time', 'acr', 'nonce', 'preferred_username', 'name', 'tid', 'ver', 'at_hash', 'c_hash', 'email'], 'kerberos_endpoint': 'https://login.microsoftonline.com//kerberos', 'tenant_region_scope': 'EU', 'cloud_instance_name': 'microsoftonline.com', 'cloud_graph_host_name': 'graph.windows.net', 'msgraph_host': 'graph.microsoft.com', 'rbac_url': 'https://pas.windows.net'} msal.application: Broker enabled? True cli.azure.cli.core.auth.credential_adaptor: CredentialAdaptor.get_token: scopes=('https://pas.windows.net/CheckMyAccess/Linux/.default',), kwargs={'data': {'token_type': 'ssh-cert', 'req_cnf': '{"kty": "RSA", "n": "", "e": "AQAB", "kid": ""}', 'key_id': ''}} cli.azure.cli.core.auth.msal_authentication: UserCredential.get_token: scopes=('https://pas.windows.net/CheckMyAccess/Linux/.default',), claims=None, kwargs={'data': {'token_type': 'ssh-cert', 'req_cnf': '{"kty": "RSA", "n": "", "e": "AQAB", "kid": ""}', 'key_id': ''}} msal.broker: [MSAL:0001] INFO LogTelemetryData:332 Printing Telemetry for Correlation ID: b3819a8b-0a63-4a7b-a567-bb8d2acf234b msal.broker: [MSAL:0001] INFO LogTelemetryData:340 Key: start_time, Value: 2023-08-08T15:50:29.000Z msal.broker: [MSAL:0001] INFO LogTelemetryData:340 Key: api_name, Value: ReadAccountById msal.broker: [MSAL:0001] INFO LogTelemetryData:340 Key: was_request_throttled, Value: false msal.broker: [MSAL:0001] INFO LogTelemetryData:340 Key: request_duration, Value: 0 msal.broker: [MSAL:0001] INFO LogTelemetryData:340 Key: authority_type, Value: Unknown msal.broker: [MSAL:0001] INFO LogTelemetryData:340 Key: msal_version, Value: 1.1.0+local msal.broker: [MSAL:0001] INFO LogTelemetryData:340 Key: correlation_id, Value: b3819a8b-0a63-4a7b-a567-bb8d2acf234b msal.broker: [MSAL:0001] INFO LogTelemetryData:340 Key: stop_time, Value: 2023-08-08T15:50:29.000Z msal.broker: [MSAL:0001] INFO LogTelemetryData:340 Key: msalruntime_version, Value: 0.13.9 msal.broker: [MSAL:0001] INFO LogTelemetryData:340 Key: is_successful, Value: true msal.broker: [MSAL:0002] INFO SetCorrelationId:220 Set correlation ID: b3819a8b-0a63-4a7b-a567-bb8d2acf234b msal.broker: [MSAL:0002] INFO EnqueueBackgroundRequest:677 The original authority is 'https://login.microsoftonline.com/' msal.broker: [MSAL:0002] INFO ModifyAndValidateAuthParameters:182 Additional query parameter added successfully. Key: '(pii)' Value: '(pii)' msal.broker: [MSAL:0002] INFO ModifyAndValidateAuthParameters:182 Additional query parameter added successfully. Key: '(pii)' Value: '(pii)' msal.broker: [MSAL:0002] INFO ModifyAndValidateAuthParameters:182 Additional query parameter added successfully. Key: '(pii)' Value: '(pii)' msal.broker: [MSAL:0002] INFO ModifyAndValidateAuthParameters:199 Authority Realm: ************************* msal.broker: [MSAL:0003] INFO LogTelemetryData:332 Printing Telemetry for Correlation ID: b3819a8b-0a63-4a7b-a567-bb8d2acf234b msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: start_time, Value: 2023-08-08T15:50:29.000Z msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: api_name, Value: AcquireTokenSilently msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: was_request_throttled, Value: false msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: request_duration, Value: 40 msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: authority_type, Value: AAD msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: access_token_expiry_time, Value: 2023-08-08T16:21:26.000Z msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: read_token, Value: ID|AT msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: msal_version, Value: 1.1.0+local msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: client_id, Value: ************************* msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: correlation_id, Value: b3819a8b-0a63-4a7b-a567-bb8d2acf234b msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: stop_time, Value: 2023-08-08T15:50:29.000Z msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: msalruntime_version, Value: 0.13.9 msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: original_authority, Value: https://login.microsoftonline.com/ msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: request_eligible_for_broker, Value: true msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: broker_app_used, Value: false msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: additional_query_parameters_count, Value: 3 msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: auth_flow, Value: AT msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: is_successful, Value: true msal.broker: [MSAL:0003] INFO LogTelemetryData:340 Key: authorization_type, Value: WindowsIntegratedAuth msal.broker: [MSAL:0003] INFO LogTelemetryData:345 Printing Execution Flow: msal.broker: [MSAL:0003] INFO LogTelemetryData:353 {"t":"8b2yn","tid":3,"ts":0,"l":2},{"t":"8dqkx","tid":3,"ts":0,"l":2},{"t":"8dqik","tid":3,"ts":0,"l":2},{"t":"8b2ht","tid":3,"ts":0,"l":2},{"t":"7e60d","tid":3,"ts":0,"l":2,"a":2,"ie":0},{"t":"7e60e","tid":3,"ts":0,"l":2,"a":2,"ie":1},{"t":"8dqin","tid":3,"ts":0,"l":2},{"t":"7e60f","tid":3,"ts":0,"l":2,"a":2,"ie":0},{"t":"7e60g","tid":3,"ts":11,"l":2,"a":2,"ie":1},{"t":"7e60h","tid":3,"ts":11,"l":2,"a":2,"ie":0},{"t":"7e60i","tid":3,"ts":12,"l":2,"a":2,"ie":1},{"t":"8dqit","tid":3,"ts":12,"l":2},{"t":"6xuag","tid":3,"ts":12,"l":2} msal.token_cache: event={ "_account_id": "", "client_id": "", "data": { "key_id": "", "req_cnf": "{"kty": "RSA", "n": "", "e": "AQAB", "kid": ""}", "token_type": "ssh-cert" }, "response": { "_account_id": "", "_msalruntime_telemetry": { "access_token_expiry_time": "2023-08-08T16:21:26.000Z", "additional_query_parameters_count": "3", "api_name": "AcquireTokenSilently", "auth_flow": "AT", "authority_type": "AAD", "authorization_type": "WindowsIntegratedAuth", "broker_app_used": "false", "client_id": "", "correlation_id": "b3819a8b-0a63-4a7b-a567-bb8d2acf234b", "is_successful": "true", "msal_version": "1.1.0+local", "msalruntime_version": "0.13.9", "original_authority": "https://login.microsoftonline.com/", "read_token": "ID|AT", "request_duration": "40", "request_eligible_for_broker": "true", "start_time": "2023-08-08T15:50:29.000Z", "stop_time": "2023-08-08T15:50:29.000Z", "was_request_throttled": "false" }, "access_token": "", "client_info": "", "expires_in": 1857, "id_token": "", "id_token_claims": "***", "scope": "https://pas.windows.net/CheckMyAccess/Linux/user_impersonation https://pas.windows.net/CheckMyAccess/Linux/.default", "token_type": "ssh-cert" }, "scope": [ "https://pas.windows.net/CheckMyAccess/Linux/user_impersonation", "https://pas.windows.net/CheckMyAccess/Linux/.default" ], "token_endpoint": "https://login.microsoftonline.com//oauth2/v2.0/token" } cli.azext_ssh.custom: Generating certificate C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa.pub-aadcert.pub cli.azext_ssh.ssh_utils: Platform architecture: 32bit cli.azext_ssh.ssh_utils: OS architecture: 64bit cli.azext_ssh.ssh_utils: System Root: C:\Windows cli.azext_ssh.ssh_utils: Attempting to run ssh-keygen from path C:\Windows\SysNative\openSSH\ssh-keygen.exe cli.azext_ssh.ssh_utils: Running ssh-keygen command C:\Windows\SysNative\openSSH\ssh-keygen.exe -L -f C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa.pub-aadcert.pub cli.azext_ssh.ssh_utils: Platform architecture: 32bit cli.azext_ssh.ssh_utils: OS architecture: 64bit cli.azext_ssh.ssh_utils: System Root: C:\Windows cli.azext_ssh.ssh_utils: Attempting to run ssh from path C:\Windows\SysNative\openSSH\ssh.exe cli.azext_ssh.ssh_utils: Running ssh command C:\Windows\SysNative\openSSH\ssh.exe 192.168.1.5 -l [email protected] -i C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa -o CertificateFile="C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa.pub-aadcert.pub" -vvv OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2 debug3: Failed to open file:C:/Users/user/.ssh/config error:2 debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2 debug2: resolve_canonicalize: hostname 192.168.1.5 is address debug2: ssh_connect_direct debug1: Connecting to 192.168.1.5 [192.168.1.5] port 22. debug1: Connection established. debug1: identity file C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa type 0 debug1: certificate file C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa.pub-aadcert.pub type 4 debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.1 debug1: Remote protocol version 2.0, remote software version OpenSSH_8.9p1 Ubuntu-3ubuntu0.3 debug1: match: OpenSSH_8.9p1 Ubuntu-3ubuntu0.3 pat OpenSSH compat 0x04000000 debug2: fd 3 setting O_NONBLOCK debug1: Authenticating to 192.168.1.5:22 as '[email protected]' debug3: hostkeys_foreach: reading file "C:\Users\user/.ssh/known_hosts" debug3: record_hostkey: found key type ECDSA in file C:\Users\user/.ssh/known_hosts:1 debug3: load_hostkeys: loaded 1 keys from 192.168.1.5 debug3: Failed to open file:C:/Users/user/.ssh/known_hosts2 error:2 debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts error:2 debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts2 error:2 debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521 debug3: send packet: type 20 debug1: SSH2_MSG_KEXINIT sent debug3: receive packet: type 20 debug1: SSH2_MSG_KEXINIT received debug2: local client KEXINIT proposal debug2: KEX algorithms: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c debug2: host key algorithms: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],[email protected],[email protected],ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected] debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected] debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1 debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1 debug2: compression ctos: none,[email protected],zlib debug2: compression stoc: none,[email protected],zlib debug2: languages ctos: debug2: languages stoc: debug2: first_kex_follows 0 debug2: reserved 0 debug2: peer server KEXINIT proposal debug2: KEX algorithms: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,[email protected],diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256 debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519 debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected] debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected] debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1 debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1 debug2: compression ctos: none,[email protected] debug2: compression stoc: none,[email protected] debug2: languages ctos: debug2: languages stoc: debug2: first_kex_follows 0 debug2: reserved 0 debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ecdsa-sha2-nistp256 debug1: kex: server->client cipher: [email protected] MAC: compression: none debug1: kex: client->server cipher: [email protected] MAC: compression: none debug3: send packet: type 30 debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug3: receive packet: type 31 debug1: Server host key: ecdsa-sha2-nistp256 SHA256:* debug3: hostkeys_foreach: reading file "C:\Users\user/.ssh/known_hosts" debug3: record_hostkey: found key type ECDSA in file C:\Users\user/.ssh/known_hosts:1 debug3: load_hostkeys: loaded 1 keys from 192.168.1.5 debug3: Failed to open file:C:/Users/user/.ssh/known_hosts2 error:2 debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts error:2 debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts2 error:2 debug1: Host '192.168.1.5' is known and matches the ECDSA host key. debug1: Found key in C:\Users\user/.ssh/known_hosts:1 debug3: send packet: type 21 debug2: set_newkeys: mode 1 debug1: rekey out after 134217728 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug3: receive packet: type 21 debug1: SSH2_MSG_NEWKEYS received debug2: set_newkeys: mode 0 debug1: rekey in after 134217728 blocks debug3: unable to connect to pipe \\.\pipe\openssh-ssh-agent, error: 2 debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory debug1: Will attempt key: C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa.pub-aadcert.pub RSA-CERT SHA256:************************* explicit debug1: Will attempt key: C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa RSA SHA256:************************* explicit debug2: pubkey_prepare: done debug3: send packet: type 5 debug3: receive packet: type 7 debug1: SSH2_MSG_EXT_INFO received debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected]> debug1: kex_input_ext_info: [email protected] (unrecognised) debug3: receive packet: type 6 debug2: service_accept: ssh-userauth debug1: SSH2_MSG_SERVICE_ACCEPT received debug3: send packet: type 50 debug3: receive packet: type 51 debug1: Authentications that can continue: publickey debug3: start over, passed a different list publickey debug3: preferred publickey,keyboard-interactive,password debug3: authmethod_lookup publickey debug3: remaining preferred: keyboard-interactive,password debug3: authmethod_is_enabled publickey debug1: Next authentication method: publickey debug1: Offering public key: C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa.pub-aadcert.pub RSA-CERT SHA256:************************* explicit debug3: send packet: type 50 debug2: we sent a publickey packet, wait for reply debug3: receive packet: type 60 debug1: Server accepts key: C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa.pub-aadcert.pub RSA-CERT SHA256:************************* explicit debug3: sign_and_send_pubkey: RSA-CERT SHA256:************************* debug1: sign_and_send_pubkey: no separate private key for certificate "C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa.pub-aadcert.pub" debug3: sign_and_send_pubkey: signing using [email protected] debug3: Bad permissions. Try removing permissions for user: XXXXXXXXXXXX\None (S-1-5-21-1488898208-1225971280-3526109899-513) on file C:/Users/user/AppData/Local/Temp/2/aadsshcertt5ck7_gk/id_rsa.pub-aadcert.pub. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions for 'C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa.pub-aadcert.pub' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. Load key "C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa.pub-aadcert.pub": bad permissions debug1: Offering public key: C:\Users\user\AppData\Local\Temp\2\aadsshcertt5ck7_gk\id_rsa RSA SHA256:************************* explicit debug3: send packet: type 50 debug2: we sent a publickey packet, wait for reply debug3: receive packet: type 51 debug1: Authentications that can continue: publickey debug2: we did not send a packet, disable method debug1: No more authentication methods to try. [email protected]@192.168.1.5: Permission denied (publickey). cli.knack.cli: Event: CommandInvoker.OnTransformResult [<function _resource_group_transform at 0x03B90CD0>, <function _x509_from_base64_to_hex_transform at 0x03B90D18>] [0m ute []

C:\Users\user>

Expected behavior

The SSH connection to the Linux VM should directly open.

Environment Summary

C:\Users\user>az --version azure-cli 2.51.0

core 2.51.0 telemetry 1.1.0

Extensions: ssh 2.0.1

Dependencies: msal 1.24.0b1 azure-mgmt-resource 23.1.0b2

Python location 'C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe' Extensions directory 'C:\Users\user.azure\cliextensions'

Python (Windows) 3.10.10 (tags/v3.10.10:aad5f6a, Feb 7 2023, 17:05:00) [MSC v.1929 32 bit (Intel)]

Legal docs and information: aka.ms/AzureCliLegal

Your CLI is up-to-date.

C:\Users\user>

Additional context

No response

lb-cyway-one avatar Aug 08 '23 16:08 lb-cyway-one

Hi @lb-cyway-one,

2.51.0 is not the latest Azure CLI(2.57.0).

If you haven't already attempted to do so, please upgrade to the latest Azure CLI version by following https://learn.microsoft.com/en-us/cli/azure/update-azure-cli.

Thank you for opening this issue, we will look into it.

yonzhan avatar Aug 08 '23 16:08 yonzhan

I've got the very same issue, should I provide more information?

Attoy avatar Aug 09 '23 14:08 Attoy

Thank you for opening this issue, we will look into it.

Any news on this matter?

Attoy avatar Aug 29 '23 07:08 Attoy

I just started experiencing this today. It doesn't happen on every connection - I've been allowed through to my VMs in a few instances. It does fail more often than it doesn't however.

I tried updating the ssh extension to 2.0.1 from 1.0.4, no change

first-caveman avatar Sep 04 '23 01:09 first-caveman

I'd like to add that if I downgrade the az cli to 2.49.0 the issue vaishes and it presents itself again as soon as I upgrade the az cli to 2.50.0 and 2.51.0

Edit: same issue with 2.52.0 32bit and 64bit

Attoy avatar Sep 04 '23 06:09 Attoy

Also experiencing this with 2.53.0 32bit and 64bit

github-wcha avatar Sep 25 '23 00:09 github-wcha

Same here with 2.53.0

igor-teresco avatar Oct 19 '23 12:10 igor-teresco

Same issue with 2.53.1 32bit and 64bit

Can we have an update on this issue pls?

lrebosio avatar Oct 26 '23 15:10 lrebosio

We will investigate this issue. Can someone who can repro this issue check two scenarios and let us know if it still fails:

  1. Use the --credentials-folder parameter to save the credentials to a local folder where only the user has permissions
  2. Use ssh-keygen to generate the key pair before starting the connection, and provide the path to the generated private key with the -i parameter in the az ssh vm command.

vthiebaut10 avatar Nov 20 '23 20:11 vthiebaut10

@vthiebaut10 thank you for the follow-up. Just tried right now but I cannot reproduce the error anymore. "az ssh vm --ip 192.168.1.5" is now working without any specific option or changes on folder permissions.

lb-cyway-one avatar Nov 21 '23 09:11 lb-cyway-one

We will investigate this issue. Can someone who can repro this issue check two scenarios and let us know if it still fails:

  1. Use the --credentials-folder parameter to save the credentials to a local folder where only the user has permissions

It doesn't even recognize the option --credentials-folder

  1. Use ssh-keygen to generate the key pair before starting the connection, and provide the path to the generated private key with the -i parameter in the az ssh vm command.

I tried, the az ssh vm command ignores the key I point to with the -i parameter, the error is the following: Load key "C:\Users\***********\.ssh\id_rsa.pub-aadcert.pub": bad permissions ***********@xx.xx.xxx.xxx: Permission denied (publickey).

the keyfile I use with the -i parameters is named test_id_rsa / test_id_rsa.pub

lrebosio avatar Nov 21 '23 10:11 lrebosio

@jiasli @yonzhan - Could you help me locate someone in the Azure CLI team that might know what changes in the latest versions of Azure CLI could affect the logic to set the permissions in the files in Windows? Currently the module uses the oschmod module to do so. I posted in the internal channel, but didn't get a response.

vthiebaut10 avatar Nov 27 '23 15:11 vthiebaut10

@lrebosio and everyone who is able to repro the issue: Since I can't repro the error, it's been a little difficult to find the root cause of the behavior. Can you run the "az ssh config" command to the same vm you are getting an error? For the -f/--file just do something in the "C:\Users\***********\.ssh" folder and one in the temp folder.

az ssh config --name <vmname> --resource-group <rg> --file C:\Users\<username>\.ssh\myconfig And then check the permissions of the created certificate in C:\Users\<username>\.ssh\az_ssh_config\<rg>-<vmname>\id_rsa.pub-aadcert.pub. Just right click on that file, select Properties > Security > Advanced, and let me know what permissions are set.

Then run az ssh config --name <vmname> --resource-group <rg> --file <temp_folder>\myconfig And then check the permissions in the certificate in <temp_folder>\az_ssh_config

I'm trying to see if the problem is if there is some special permission that is not being reset by the module.

vthiebaut10 avatar Nov 27 '23 19:11 vthiebaut10

Hello @vthiebaut10,

az ssh config --name <vmname> --resource-group <rg> --file C:\Users\<username>\.ssh\myconfig C:\Users\<username>\.ssh\az_ssh_config\<vmname>\id_rsa.pub-aadcert.pub file has the following permissions entries: SYSTEM - Allow - Full Control - None my user - Allow - Special - None Users - Allow - Read - None

az ssh config --name <vmname> --resource-group <rg> --file <temp_folder>\myconfig C:\Users\<username>\AppData\Local\Temp\az_ssh_config\<vmname>\id_rsa.pub-aadcert.pub file has the following permissions entries which are the same as before: SYSTEM - Allow - Full Control - None my user - Allow - Special - None Users - Allow - Read - None

lrebosio avatar Nov 28 '23 08:11 lrebosio

I have the same issue when connecting using Bastion

az --version azure-cli 2.54.0 core 2.54.0 telemetry 1.1.0 Extensions: bastion 0.2.5 ssh 2.0.2 webapp 0.4.0 Dependencies: msal 1.24.0b2 azure-mgmt-resource 23.1.0b2 Python location 'C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe' Extensions directory 'C:\Users\kent.azure\cliextensions'

Python (Windows) 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)]

Command I use is... az network bastion ssh --name ($Bastion.Name) --resource-group ($Bastion.resourceGroup) --target-resource-id ($AzureVM.Id) --auth-type "AAD"

Running in PS7 (x64) console.

KentNordstrom avatar Nov 28 '23 12:11 KentNordstrom

I have tried to figure out if I can see some common reasons for this to happen... When I look at the documentation at https://learn.microsoft.com/en-us/entra/architecture/auth-ssh#components-ofthe-system and combine it with the times I see this error occur...

I have tested some and it seems to me that this error occur when there is still a valid SSH key from earlier authentications when I try again. I will do some more testing but it would be nice if someone else could also confirm my suspected reason for when this error is occuring.

KentNordstrom avatar Dec 04 '23 16:12 KentNordstrom

@KentNordstrom Thank you for investigating! Can you clarify what you mean by "this error occur when there is still a valid SSH key from earlier authentications when I try again"? What are the steps to repro that behavior? The keys and certificates should be deleted once the command terminates, so how are you maintaining the key from early authentications?

vthiebaut10 avatar Dec 04 '23 16:12 vthiebaut10

@KentNordstrom Thank you for investigating! Can you clarify what you mean by "this error occur when there is still a valid SSH key from earlier authentications when I try again"? What are the steps to repro that behavior? The keys and certificates should be deleted once the command terminates, so how are you maintaining the key from early authentications?

When you authenticate an SSH keypair with one hour validity is generated. If you try again while that SSH keypair is still valid, az ssh still generates a new keypair and tries to use that newly created one instead of the current still active key pair. image I still need to run some more tests, but this is so far the closest I got to understand when/why I run into this error.

KentNordstrom avatar Dec 04 '23 17:12 KentNordstrom

I have been able to make some further testing and can conclude that my finding seem to support my theory around multiple instances of valid SSH keys present in the client system and/or on the target.

The below actions where all done in the same PS7 console without closing it or restarting anything.

Time 07:42 I login using az network bastion ssh... and get a new temporary SSH key valid for one hour

Generated SSH certificate C:\Users\kent\AppData\Local\Temp\aadsshcertgbyoo9no\id_rsa.pub-aadcert.pub is valid until 2023-12-05 08:47:42 in local time.

Time 08:30 I do a logout

Time 08:35 I login using az network bastion ssh... and get a new copy of the still valid SSH key. But it's puts the copy in a new folder in the Temp directory and I now have two copies of the same key in my system. I did a comparison and the id_rsa.pub-aadcert.pub files in the two temp directories are identical.

Generated SSH certificate C:\Users\kent\AppData\Local\Temp\aadsshcertagc4243z\id_rsa.pub-aadcert.pub is valid until 2023-12-05 08:47:42 in local time.

I now get the error message... @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions for 'C:\Users\kent\AppData\Local\Temp\aadsshcertagc4243z\id_rsa.pub-aadcert.pub' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. Load key "C:\Users\kent\AppData\Local\Temp\aadsshcertagc4243z\id_rsa.pub-aadcert.pub": bad permissions [email protected]@localhost: Permission denied (publickey).

Time 08:50 the temporary SSH key I generated is now no longer valid. I login using az network bastion ssh... and get a new temporary SSH key valid for one hour

Generated SSH certificate C:\Users\kent\AppData\Local\Temp\aadsshcert2bfycp7e\id_rsa.pub-aadcert.pub is valid until 2023-12-05 09:50:58 in local time.

and now the error is gone and it works as expected.

KentNordstrom avatar Dec 05 '23 08:12 KentNordstrom