{"id":202,"date":"2017-10-17T20:03:54","date_gmt":"2017-10-17T20:03:54","guid":{"rendered":"http:\/\/cheapwindowsvps.com\/blog\/?p=202"},"modified":"2025-01-24T08:46:37","modified_gmt":"2025-01-24T08:46:37","slug":"how-to-add-a-samba-user-on-linux","status":"publish","type":"post","link":"https:\/\/cheapwindowsvps.com\/blog\/how-to-add-a-samba-user-on-linux\/","title":{"rendered":"How to add a Samba User on Linux"},"content":{"rendered":"<p><a href=\"https:\/\/www.samba.org\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Samba<\/span><\/a><span style=\"font-weight: 400;\"> is a file-sharing service that can connect two or more computers on a network- you can even share files between Linux and Windows machines. But what happens when you get a new coworker who needs to be added to the share?<\/span><\/p>\n<p><span style=\"font-weight: 400;\">This article assumes that you already have a Samba server set up and running.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Here is the process for adding a Samba user on Linux.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Make a System User for Samba on Linux<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">If the new user does not exist on the server already, you\u2019ll need to add a new user account. Say our new coworker\u2019s name is Sam.<\/span><\/p>\n<blockquote><p><span style=\"font-weight: 400;\"># sudo useradd sam<\/span><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">Of course, there are many options you can pass to useradd to give this user more or less permissions and abilities within the system. For now, we\u2019re just setting him up as a default user.<\/span><\/p>\n<p><b>Note:<\/b><span style=\"font-weight: 400;\"> This username must be the same as the user on the other connecting systems. Otherwise, you can map the usernames using a configuration option in <\/span><span style=\"font-weight: 400;\">smb.conf<\/span><span style=\"font-weight: 400;\">. For example if Sam\u2019s Windows username is SamB, you can use what\u2019s called \u201cuser mapping\u201d to connect them.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">User Mapping on Samba<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">In <\/span><span style=\"font-weight: 400;\">\/etc\/samba\/smb.conf<\/span><span style=\"font-weight: 400;\"> is a configuration option that allows you to provide a mapping of usernames for Linux to Windows. So if Sam is \u201csam\u201d on Linux and \u201cSamB\u201d on Windows, this is how you\u2019d set it up.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">First, in <\/span><span style=\"font-weight: 400;\">\/etc\/samba\/smb.conf<\/span><span style=\"font-weight: 400;\">, specify where the file that has the mapping lives:<\/span><\/p>\n<blockquote><p><span style=\"font-weight: 400;\">username map = \/path\/to\/mapping.txt<\/span><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">Now we need to create the mapping file itself. Be sure you create the file in the same location specified in smb.conf. Using one line per user, the mappings follow this format:<\/span><\/p>\n<blockquote><p><span style=\"font-weight: 400;\">![server_user] = [client_user]<\/span><\/p><\/blockquote>\n<h2><span style=\"font-weight: 400;\">Define Samba Password<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Now that the user account is on the server, we need to tell Samba about it. <\/span><\/p>\n<blockquote><p><span style=\"font-weight: 400;\"># smbpasswd -a sam<\/span><\/p>\n<p><span style=\"font-weight: 400;\">New SMB password: ********<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Retype new SMB password: ********<\/span><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">This password can be different from the password that Sam uses to log in. The Samba password file and the Linux password file are separate, so Samba only knows about passwords in smbpasswd.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Add to smb.conf in Samba<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Finally, we need to add our new user to the list of allowed users on Samba. You can find this list in the <\/span><span style=\"font-weight: 400;\">\/etc\/samba\/smb.conf<\/span><span style=\"font-weight: 400;\"> file. <\/span><\/p>\n<p><span style=\"font-weight: 400;\">If you already have a share set up, you\u2019ll see a section that looks something like this:<\/span><\/p>\n<blockquote><p><span style=\"font-weight: 400;\">[sharedir]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">comment = Shared data directory<\/span><\/p>\n<p><span style=\"font-weight: 400;\">path = \/data\/shared<\/span><\/p>\n<p><span style=\"font-weight: 400;\">valid users = al kevin<\/span><\/p>\n<p><span style=\"font-weight: 400;\">public = no<\/span><\/p>\n<p><span style=\"font-weight: 400;\">writable = yes<\/span><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">If you want to add Sam to sharedir, then you need to put his Samba name on the line that says \u201cvalid users.\u201d<\/span><\/p>\n<blockquote><p><span style=\"font-weight: 400;\">[sharedir]<\/span><\/p>\n<p><span style=\"font-weight: 400;\">comment = Shared data directory<\/span><\/p>\n<p><span style=\"font-weight: 400;\">path = \/data\/shared<\/span><\/p>\n<p><span style=\"font-weight: 400;\">valid users = al kevin sam<\/span><\/p>\n<p><span style=\"font-weight: 400;\">public = no<\/span><\/p>\n<p><span style=\"font-weight: 400;\">writable = yes<\/span><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">There, we\u2019ve added Sam. Save and close the file. There\u2019s one more step to do before Sam can access the share, though.<\/span><\/p>\n<h2><span style=\"font-weight: 400;\">Restart Samba<\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Once you\u2019ve saved your changes, you\u2019ll need to restart Samba to see the new permissions take effect.<\/span><\/p>\n<blockquote><p><span style=\"font-weight: 400;\">$ sudo service smbd start <\/span><\/p><\/blockquote>\n<p><span style=\"font-weight: 400;\">At this point, the new user should have access to the Samba network share.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Samba is a file-sharing service that can connect two or more computers on a network- you can even share files between Linux and Windows machines. But what happens when you get a new coworker who needs to be added to the share? This article assumes that you already have a Samba server set up and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-202","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/comments?post=202"}],"version-history":[{"count":10,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/202\/revisions"}],"predecessor-version":[{"id":10545,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/202\/revisions\/10545"}],"wp:attachment":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media?parent=202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/categories?post=202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/tags?post=202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}