Description\n-----------\n\nThe unix_socket authentication plugin is installed by default, and it is used by the 'root'@'localhost' user account by default. See Authentication for more information.\n\nThe unix_socket authentication plugin allows the user to use operating system credentials when connecting to MariaDB via the local Unix socket file. This Unix socket file is defined by the socket system variable.\n\nThe unix_socket authentication plugin works by calling the getsockopt system call with the SO_PEERCRED socket option, which allows it to retrieve the uid of the process that is connected to the socket. It is then able to get the user name associated with that uid. Once it has the user name, it will authenticate the connecting user as the MariaDB account that has the same user name.\n\nThe unix_socket authentication plugin is not suited to multiple Unix users accessing a single MariaDB user account.\n\nSecurity\n\nA unix_socket authentication plugin is a passwordless security mechanism. Its security lies in the strength of the access to the Unix user, rather than the complexity and the secrecy of the password.\n\nAs security differs from password security, the strengths and weaknesses need to be considered, and those can differ depending on the specific installation.\n\nStrengths\n\n Access is limited to the Unix user so, for example, a www-data user cannot access root with the unix_socket authentication plugin.\n There is no password which can be cracked by brute force.\n There is no password that can be accidentally exposed by user accident, poor security on backups, or poor security on passwords in configuration files.\n Default Unix user security is usually strong on preventing remote access and password brute force attempts.\n\nWeaknesses\n\nThe strength of a unix_socket authentication plugin is effectively the strength of the security of the Unix users on the system. In most cases, the Unix user default installation is sufficiently secure. However, the following is a non-exhaustive list of potential Unix user security issues that may arise.\n\n Common access areas without screen locks, where an unauthorized user accesses the logged in Unix user of an authorized user.\n Extensive sudo access grants that provide users with access to execute commands of a different Unix user.\n Scripts writable by Unix users other than the Unix user that are executed (via cron or directly) by the Unix user.\n Web pages that are susceptible to command injection, where the Unix user running the web page has elevated privileges in the database that weren't intended to be used.\n Poor Unix user password practices including weak user passwords, password exposure and password reuse accompanied by an access vulnerability/mechanism of an unauthorized user to exploit this weakness.\n Weak remote access mechanisms and network file system privileges.\n Poor user security behavior including running untrusted scripts and software.\n\nIn some of these scenarios a database password may prevent these security exploits, however it will remove all the strengths of the unix_socket authentication plugin previously mentioned.\n\nDisabling the Plugin\n\nThe unix_socket authentication plugin is installed by default.\n\nIf you do not want it to be available by default, you must disable it.\n\nThe unix_socket authentication plugin is also installed by default in new installations that use the .deb packages provided by Debian's default repositories and Ubuntu's default repositories. See Differences in MariaDB in Debian (and Ubuntu) for more information.\n\nThe unix_socket authentication plugin can be disabled by starting the server with the unix_socket option set to OFF. This can be specified as a command-line argument to mysqld or it can be specified in a relevant server option group in an option file:\n\n``ini\n[mariadb]\n...\nunix_socket=OFF\n`\n\nAs an alternative, the unix_socket option can also be set to OFF by pairing the option with the disable option prefix:\n\n`ini\n[mariadb]\n...\ndisable_unix_socket\n`\n\nInstalling the Plugin\n\nThe unix_socket authentication plugin is installed by default in almost all MariaDB server versions. If you work with a version that doesn't have the plugin installed, you can install it as described in one of the following ways.\n\n Install the plugin without restarting the server. You can install the plugin dynamically, by executing INSTALL SONAME or INSTALL PLUGIN:\n\n`sql\nINSTALL SONAME 'auth_socket';\n`\n\n Instruct the server to load the plugin at startup. The plugin can be installed this way by providing the --plugin-load or the --plugin-load-add options. This can be specified as a command-line argument to mysqld or it can be specified in a relevant server option group in an option file:\n\n`ini\n[mariadb]\n...\nplugin_load_add = auth_socket\n`\n\nUninstalling the Plugin\n\nYou can uninstall the plugin dynamically by executing UNINSTALL SONAME or UNINSTALL PLUGIN:\n\n`sql\nUNINSTALL SONAME 'auth_socket';\n`\n\nIf you installed the plugin by providing the --plugin-load or the --plugin-load-add options in a server option group in an option file, those options should be removed to prevent the plugin from being loaded the next time the server is restarted.\n\nCreating Users\n\nTo create a user account via CREATE USER, specify the name of the plugin in the IDENTIFIED VIA clause:\n\n`sql\nCREATE USER username@hostname IDENTIFIED VIA unix_socket;\n`\n\nIf SQL_MODE does not have NO_AUTO_CREATE_USER set, then you can also create the user account via GRANT:\n\n`sql\nGRANT SELECT ON db. TO username@hostname IDENTIFIED VIA unix_socket;\n`\n\nThe authentication string (if present) is compared with the socket's user name. Authentication proceeds if there's a match. In this case, the external_user system variable contains the OS user.\n\nConsider an OS user named 'bob' that has been created like this:\n\n`sql\nCREATE USER A identified via unix_socket as 'bob';\n\n`\n\nThat user can connect like this:\n\n`bash\nmariadb -uA\n`\n\nAlternatively, accessing the sock file directly, the user can connect like this:\n\n`bash\nmariadb -uA -S /var/run/mysqld/mysqld.sock\n`\n\nOnce connected, you can view that user like this:\n\n`sql\nSELECT USER(),@@external_user;\n+-------------+-----------------+\n| user()      | @@external_user |\n+-------------+-----------------+\n| A@localhost | bob             |\n+-------------+-----------------+\n`\n\nThe plugin only checks whether the OS socket user id matches the MariaDB user name. It ignores the authentication string.\n\nSwitching to Password-Based Authentication\n\nIf Unix socket authentication does not meet your needs, you can switch a user account back to password-based authentication, by telling MariaDB to use a different authentication plugin for the account. The specific authentication plugin is specified with the IDENTIFIED VIA clause. To switch to the mysql_native_password authentication plugin, you need to do this:\n\n`sql\nALTER USER root@localhost IDENTIFIED VIA mysql_native_password;\nSET PASSWORD = PASSWORD('foo');\n`\n\nIf you use scripts that require passwordless access to MariaDB, this would cause them to break. You may be able to fix that by setting a password in the [client] option group in your /root/.my.cnf option file.\n\n`ini\n[client]\npassword=foo\n`\n\nClient Authentication Plugins\n\nThe unix_socket authentication plugin does not require any specific client authentication plugins. It should work with all clients.\n\nSupport in Client Libraries\n\nThe unix_socket` authentication plugin does not require any special support in client libraries. It should work with all client libraries.\n\nURL: https://mariadb.com/docs/server/reference/plugins/authentication-plugins/authentication-plugin-unix-socket