From OS X, I can launch RDP and login to a Windows 2022 Server Azure Edition instance with name+password. I have created a new drive Z: mapped to a storage file share using the New-PSDrive command from powershell. I can stop and start the instance and I always get the Z: drive back. Indeed, from OS X itself I can issue
open smb://myStorageAccount:<account_key>@myStorageAcccount.file.core.windows.net/myShareName
and it mounts the file share on /Volumes/xfer with POSIX compliance so my OS X and Windows directory view is the same; very handy.
I tried to add SSH in hopes of being able to do something like:
ssh -i keyfile.pem remoteUser@remoteIP powershell set-of-commands
I opened port 22 on the instance network security group and installed OpenSSH Server. I can ssh into the machine using name+password. I'd like to login with ssh -i keyfile.pem so I put my public key into C:\Users\remoteUser\.ssh\authorized_keys but -i option still prompts for password. Let's consider this problem #2 to solve.
Problem #1 is after ssh login, I start a powershell and the 'Z:' drive is not there. Are drive mappings scoped only to the RDP instance? I am used to OS X / Linux where a filesystem mount is available (subject to permissions) to all.
I set up the Z: using the very helpful script on the file share create page that looks like this:
$connectTestResult = Test-NetConnection -ComputerName test1diag427.file.core.windows.net -Port 445
if ($connectTestResult.TcpTestSucceeded) {
# Save the password so the drive will persist on reboot
cmd.exe /C "cmdkey /add:`"myStorageAccount.file.core.windows.net`" /user:`"localhost\mySTorageAccount`" /pass:`"<account_key>`""
# Mount the drive
New-PSDrive -Name Z -PSProvider FileSystem -Root "\\myStorageAccount.file.core.windows.net\myShareName" -Persist
} else {
Write-Error -Message "Unable to reach the Azure storage account via port 445. Check to make sure your organization or ISP is not blocking port 445, or use Azure P2S VPN, Azure S2S VPN, or Express Route t\
o tunnel SMB traffic over a different port."
}
and this worked for the initial RDP session. When I try:
New-PSDrive -Name Z -PSProvider FileSystem -Root "\\myStorageAccount.file.core.windows.net\myShareName" -Persist -Cred <account_key>
it just hangs. In fact, I cannot even use Ctrl+C to break out; I have to wait 60 seconds or so then issue ~. to get the local ssh client to break the connection. And when I try the cmd.exe /C "cmdkey /add command before New-PSDrive without the -Cred option, I get this error:
CMDKEY: Credentials cannot be saved from this logon session.
So I am thinking I am fundamentally not understanding how login sessions and drive mappings work in Windows.
EDIT
I added -Scope Global to the New-PSDrive command, dropped the drive with Remove-PSDrive Z, then made sure to dot-source the script. No change in behavior. RDP session sees Z: but other ssh session does not.
Any clues on problem #1 and #2 appreciated.