Add Logins & Users to MS SQL Server
Overview
Logins can connect to the SQL server and have limited access to the master database. Users are specific to each database and must be separately created in each database to grant them access.
The login is a server-level principle and the user is a database-level principal.
Add Logins & Users
Windows
Connect to SQL server through RDP SSMS.
In the example below, the server name islocalhost
(since the machine is the host) and authentication method isWindows
, so no further input was needed.Create a new login.
In the
Object Explorer
, expandSecurity
and right-click onLogins
.Click on
New Login
.If using
Windows authentication
, clickSearch
. Then type and add authorizedLogin name
.
If usingSQL Server authentication
, setLogin name
and enterpassword
.Note:
User must change password at next login
is selected by default.Then click
Ok
.
Create a new database user.
In the
Object Explorer
, expand theDatabases
folder.Expand the database in which to create the new database user.
Right-click the
Security
folder, right-click theUsers
folder then chooseNew User
.Input the desired Username.
Click on the ellipses
(…)
to select the Login Name.In the
Select Login
window, type the login to be associated to. Confirm by clickingCheck Names
orBrowse
, then clickOk
.Then click
Ok
again to finish the new database user creation.
Linux (Ubuntu 16.04 or 18.04)
Connect by running the following command, where
servername
is the SQL server name (orlocalhost
for local connection) andsa
is the username. Notesa
is the default admin username.sqlcmd -S servername -U sa
Create a new login.
CREATE LOGIN MyLogin WITH PASSWORD = 'Password12'; GO
where
MyLogin
is the login name andPassword12
is the login password.
Create a new database user.
USE database_name; GO CREATE USER newuser FOR LOGIN MyLogin; GO
where
newuser
is the newdatabase_name
user for the loginMyLogin
.
[Optional] You can authorize other logins to create more logins and inside a database you can authorize other users to create more users.
The login
MyLogin
can create more logins and the usernewuser
can create more users within the databasedatabase_name
.
Add Admin Logins & Users
Windows
Connect to SQL server through RDP SSMS.
In the example below, the server name islocalhost
(since the machine is the host) and authentication method isWindows
, so no further input was needed.Create a New Login.
In the
Object Explorer
, expandSecurity
and right-click onLogins
.Click on
New Login
.In the
General
page:set
Login name
select
SQL Server authentication
enter
password
Note:User must change password at next login
is selected by default.
Select theÂ
Server Roles
 page in the left-menu, and then check theÂsysadmin
 check box in theÂServer roles
 list.Select theÂ
User Mapping
 page. Here, select which databases users associated to this login will have permissions to.In theÂ
Map
 column, check the box for the database that the new login can access.Â
By default, the login name appears in the User column.In theÂ
Database role membership
for list, check theÂdb_owner
 box.Click OK.
Linux (Ubuntu 16.04 or 18.04)
Connect locally by running the following command, where
servername
is the SQL server name (orlocalhost
for local connection) andsa
is the username. Notesa
is the default admin username.Create a New Login and assign admin role to it.
where
MyLogin
is the login name andPassword12
is the login password.
Create a new database user.
where
newuser
is the newdatabase_name
user for the loginMyLogin
.
Â