I've set up SSH key-based authentication from my M1 MacBook to a Windows machine for testing. I thought that connecting with my elevated credentials would let me run elevated commands like `New-PSDrive`, but that doesn't seem to be working. My public key is in the `administrators_authorized_keys` file, and I can perform elevated tasks in an RDP session without having to start PowerShell as an administrator. However, when I use the `-RunAsAdministrator` parameter with `Enter-PSSession`, I get an error. I've checked the help files and consulted with more experienced PowerShell users at work, but no one can pinpoint the issue. I should mention that I need to access the ConfigurationManager module, which isn't available on macOS. Has anyone dealt with a similar setup or have any alternative solutions?
3 Answers
It sounds like you're hitting a common issue. When you're connecting via SSH, the `-RunAsAdministrator` switch isn't applicable because your account should inherently have elevated permissions when connecting. You might want to ensure that your session is established correctly without that switch and see if that helps. Let me know how it goes!
Just to clarify, are you trying to connect from Windows to a Mac or the other way around? If you're connecting from Windows to your Mac, remember that macOS is Unix-based, so the way you elevate privileges would be with `sudo` after SSHing into your user account. It can be quite different from Windows elevation methods.
Good point about the Configuration Manager! Just so you know, it officially supports Windows PowerShell version 5.1, so if you’re trying to use it remotely with PowerShell 7, you might be dealing with a double-hop authentication issue. That could be why you're running into these limitations. It's not something I can test directly with SSH, but it's worth checking.
That's what I expected too, but unfortunately, I'm still running into problems. For some clarity, I'm using PowerShell 7 on both my Mac and the Windows machine.