Set Up Access To Network Shares
Set Up Access To Network Shares
Set Up Access To Network Shares
Windows Credentials
For most service accounts, however, you won’t be able to just log
in locally and open the Credential Manager, so we’re going to
need a little command line trickery to move on.
cmdkey
1 of 6 8/9/23, 08:48
Set up access to network shares from SQL Server | sq... https://sqlsunday.com/2021/09/02/set-up-access-to-ne...
1 cmdkey /list
1 cmdkey /delete:someserver.mycompany.local
If you know the password for the service account and you’re able
to log on locally to the server,
(https://dhmacher.files.wordpress.com/2021/09/image-1.png)
This will open up a command prompt logged in as the SQL Server
service account. If you want to make sure, run
1 whoami
Bonus: If the service runs on Local System, you can use the
SysInternals utility psExec (https://docs.microsoft.com/en-
us/sysinternals/downloads/psexec) to start a new session as
System.
2 of 6 8/9/23, 08:48
Set up access to network shares from SQL Server | sq... https://sqlsunday.com/2021/09/02/set-up-access-to-ne...
1 psexec -s -i cmd.exe
xp_cmdshell
If you don’t know the password of the service account, you can
run commands in SQL Server’s security context using
xp_cmdshell. To do this, you’ll need to be a member of the
sysadmin server role in SQL Server.
With that out of the way, you can now run commands:
1 xp_cmdshell 'whoami';
2
3 xp_cmdshell 'cmdkey /add:someserver...';
If your SQL Server Agent service uses the same service account
as the SQL Server, or if you have set up a proxy credential for the
SQL Server service account, you could create a job with an
Operating System step.
3 of 6 8/9/23, 08:48
Set up access to network shares from SQL Server | sq... https://sqlsunday.com/2021/09/02/set-up-access-to-ne...
In the same vein, you could also use SQL Server Agent to run a
PowerShell command that does the same thing. I don’t know of
any native Microsoft modules to work with Credential Store,
however. So you’d have to rely on third-party modules for this.
◦ In your storage account, find the “Access keys”. You can use
any one of them.
◦ Use cmdkey to add a credential for the storage account.
4 of 6 8/9/23, 08:48
Set up access to network shares from SQL Server | sq... https://sqlsunday.com/2021/09/02/set-up-access-to-ne...
(https://dhmacher.files.wordpress.com/2021/09/image-2.png)
If this setting is enabled, you’ll get an error message when you try
to store credentials:
AUTHENTICATION ,
CMDKEY ,
CREDENTIAL ,
WINDOWS AUTHENTICATION ,
XP_CMDSHELL
1. IE
2021-11-02 AT 18:15
Hello, I’m using a Proxy for SSIS executions in SQL Server
Agent with a stored credential (domain user,
“Mydomain\SSISExecutor”). The proxy works fine in SQL
Server Agent, when authenticating to SQL server, fileshares
etc. However, I’ve added an Azure File Share credential to the
“Mydomain\SSISExecutors” credential manager using cmdkey
– jobsteps configured to use the SSIS Proxy running
packages that tries to access the Azure File Share fails with
“The username or password is incorrect”.
Adding the same credential, using cmdkey, to the domain user
that is running the SQL Server Agent service,
“Mydomain\SQLSrvAgentRunner” – and then executing the
job step with SQL Server Agent – the package succeeds in
5 of 6 8/9/23, 08:48
Set up access to network shares from SQL Server | sq... https://sqlsunday.com/2021/09/02/set-up-access-to-ne...
REPLY
2. Peter
2023-01-28 AT 19:15
If I understand correctly, the default account for different SQL
Server services is virtual account. Does virtual account have
access to network resources? If yes, are there any differences
between virtual account and other account types (domain
account, MSA, gMSA) in terms of accessing network
resources? If there is no difference, what are the reasons to
use other account types (domain account, MSA, gMSA)?
Thanks.
REPLY
◦ Daniel Hutmacher
2023-01-28 AT 20:43
The answer to that is a long blog post in and of itself. I
would start by googling. :)
REPLY
3. Pingback: Cross-domain backup using Ola Hallengren's
scripts
6 of 6 8/9/23, 08:48