There are three ways to get your credentials into a gio command
1) Safest: via gnome keyring
as a Gnome library, gio integrates with Gnome's keyring.
If the SMB-password is present in the keyring, gio will automatically use it.
Important: for this to work, the Host in the keyring must match exactly with the URL you open with GIO (though subfolders work).
So, for the command gio mount smb://DOMAIN\;username@fileserver.your.lan/some/folder to work, the keyring must contain the credential for smb://fileserver.your.lan, for the exact user DOMAIN\username.
(host-aliases like "fileserver" or "srv003.your.lan" won't match. It's effectively a dumb string-prefix match)
The easiest way to achieve this, is to manually open the SMB server once from Nautilus/File Manager GUI, and then copy the URL it gives into your gio script.
Example: my DOMAIN\;user@fileserver.my.lan/some/folder is listed in SeaHorse (gnome keyring manager GUI) as "smb://user@fileserver.my.lan". Domain is only in the details section. Other sub-paths (e.g. /other/random/folder) would also pick up this password.
- Somewhat safe: .credentials file via stdin
The most-repeated answer is to have the answers for gio in a .credentials text file, that is piped into GIO's stdin via gio mount smb://.... < .credentials.
This is somewhat safe: It's still better than echo-style solution below, but it requires that your plaintext, unencrypted password is lying around on the filesytem, stealable for anyone who has either:
- file permissions (did you really remember to do
chmod 0600 .credentials?)
- root or sudo access (permissions? Pfah!
sudo cat .credentials laughs at your silly permissions!)
- a bootable live USB stick. (Unless you use disk-encryption, the bytes are there in plaintext on the physical storage, and live USBs have their own root powers)
3) Lazy, but terribly Unsafe: `echo PASSWORD > gio mount ...
This is the worst possible combination of all the above: Not only is your plaintext, unencrypted password readable in the script (all the downsides of .credentials above), but every user and/or logfile on your machine can see your password in the output of process-monitoring tools such as ps or top (command invocations are public).
This includes variations that encode the URL such as the example from the original question: gio mount smb://<user>:<password>@<server>/<share>/
misc note: specifying domain in URL
Finding the domain syntax took some digging, so I wanted to include it for completeness sake. (I only found it in one documentation link, that I can no longer find again)
As seen above: to specify the domain in the URL , prefix the username with YOURDOMAIN\; (replace the backslash in the windows-style DOMAIN\user with an escaped semicolon)
gio mount smb://DOMAIN\;username@fileserver.your.lan/some/folder
Note that if you use a URL in this form with interactive GIO, gio will ask for only the password. Adapt any stdin-piping to match.