Skip to content

Commit d38acdc

Browse files
Merge pull request #281970 from khdownie/kendownie071624
use credential file instead of pw
2 parents 3b69769 + 7e4af1e commit d38acdc

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

articles/storage/files/storage-how-to-use-files-linux.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: khdownie
55
ms.service: azure-file-storage
66
ms.custom: linux-related-content, devx-track-azurecli
77
ms.topic: how-to
8-
ms.date: 05/13/2024
8+
ms.date: 07/26/2024
99
ms.author: kendownie
1010
---
1111

@@ -129,7 +129,36 @@ MNT_PATH="$MNT_ROOT/$STORAGE_ACCOUNT_NAME/$FILE_SHARE_NAME"
129129
sudo mkdir -p $MNT_PATH
130130
```
131131
132-
Next, mount the file share using the `mount` command. In the following example, the `$SMB_PATH` command is populated using the fully qualified domain name for the storage account's file endpoint and `$STORAGE_ACCOUNT_KEY` is populated with the storage account key.
132+
Next, initialize the credential file by running the following script.
133+
134+
```bash
135+
# Create a folder to store the credentials for this storage account and
136+
# any other that you might set up.
137+
CREDENTIAL_ROOT="/etc/smbcredentials"
138+
sudo mkdir -p "/etc/smbcredentials"
139+
140+
# Get the storage account key for the indicated storage account.
141+
# You must be logged in with az login and your user identity must have
142+
# permissions to list the storage account keys for this command to work.
143+
STORAGE_ACCOUNT_KEY=$(az storage account keys list \
144+
--resource-group $RESOURCE_GROUP_NAME \
145+
--account-name $STORAGE_ACCOUNT_NAME \
146+
--query "[0].value" --output tsv | tr -d '"')
147+
148+
# Create the credential file for this individual storage account
149+
SMB_CREDENTIAL_FILE="$CREDENTIAL_ROOT/$STORAGE_ACCOUNT_NAME.cred"
150+
if [ ! -f $SMB_CREDENTIAL_FILE ]; then
151+
echo "username=$STORAGE_ACCOUNT_NAME" | sudo tee $SMB_CREDENTIAL_FILE > /dev/null
152+
echo "password=$STORAGE_ACCOUNT_KEY" | sudo tee -a $SMB_CREDENTIAL_FILE > /dev/null
153+
else
154+
echo "The credential file $SMB_CREDENTIAL_FILE already exists, and was not modified."
155+
fi
156+
157+
# Change permissions on the credential file so only root can read or modify the password file.
158+
sudo chmod 600 $SMB_CREDENTIAL_FILE
159+
```
160+
161+
Now you can mount the file share using the `mount` command using the credential file. In the following example, the `$SMB_PATH` command is populated using the fully qualified domain name for the storage account's file endpoint.
133162
134163
# [SMB 3.1.1](#tab/smb311)
135164
> [!NOTE]
@@ -148,7 +177,7 @@ STORAGE_ACCOUNT_KEY=$(az storage account keys list \
148177
--account-name $STORAGE_ACCOUNT_NAME \
149178
--query "[0].value" --output tsv | tr -d '"')
150179
151-
sudo mount -t cifs $SMB_PATH $MNT_PATH -o username=$STORAGE_ACCOUNT_NAME,password=$STORAGE_ACCOUNT_KEY,serverino,nosharesock,actimeo=30,mfsymlinks
180+
sudo mount -t cifs $SMB_PATH $MNT_PATH -o credentials=$SMB_CREDENTIAL_FILE,serverino,nosharesock,actimeo=30,mfsymlinks
152181
```
153182
154183
# [SMB 3.0](#tab/smb30)
@@ -165,7 +194,7 @@ STORAGE_ACCOUNT_KEY=$(az storage account keys list \
165194
--account-name $STORAGE_ACCOUNT_NAME \
166195
--query "[0].value" --output tsv | tr -d '"')
167196
168-
sudo mount -t cifs $SMB_PATH $MNT_PATH -o vers=3.0,username=$STORAGE_ACCOUNT_NAME,password=$STORAGE_ACCOUNT_KEY,serverino,nosharesock,actimeo=30,mfsymlinks
197+
sudo mount -t cifs $SMB_PATH $MNT_PATH -o vers=3.0,credentials=$SMB_CREDENTIAL_FILE,serverino,nosharesock,actimeo=30,mfsymlinks
169198
```
170199
171200
# [SMB 2.1](#tab/smb21)
@@ -182,7 +211,7 @@ STORAGE_ACCOUNT_KEY=$(az storage account keys list \
182211
--account-name $STORAGE_ACCOUNT_NAME \
183212
--query "[0].value" --output tsv | tr -d '"')
184213
185-
sudo mount -t cifs $SMB_PATH $MNT_PATH -o vers=2.1,username=$STORAGE_ACCOUNT_NAME,password=$STORAGE_ACCOUNT_KEY,serverino,nosharesock,actimeo=30,mfsymlinks
214+
sudo mount -t cifs $SMB_PATH $MNT_PATH -o vers=2.1,credentials=$SMB_CREDENTIAL_FILE,serverino,nosharesock,actimeo=30,mfsymlinks
186215
```
187216
188217
---

0 commit comments

Comments
 (0)