How to specify a password when mounting a smb share with gio?

Solution 1:

Create a file in your home directory. For example at /home/morbius/.servercreds

Into that file enter your credentials. You must specify the user name, workgroup, and password - one per line

<username>
<workgroup>
<password>

Then your gio command would look like this:

gio mount smb://<server>/<share> < /home/morbius/.servercreds

Solution 2:

To avoid creating a new file, you can pipe the input into gio.

echo -e "USERNAME\nWORKGROUP\nPASSWORD\n" | gio mount smb://<server>/<share>

echo -e tells echo to allow special characters, and \n after each field is like pressing the enter key.