{"id":244,"date":"2022-11-28T23:07:56","date_gmt":"2022-11-28T21:07:56","guid":{"rendered":"https:\/\/amsd.go.ro\/wordpress\/?p=244"},"modified":"2022-11-28T23:11:19","modified_gmt":"2022-11-28T21:11:19","slug":"setting-up-ssh-access-on-synology-storage-and-create-new-git-repository","status":"publish","type":"post","link":"https:\/\/amsd.go.ro\/wordpress\/?p=244","title":{"rendered":"Setting up SSH Access on Synology storage and Create New Git Repository"},"content":{"rendered":"\n<ul class=\"wp-block-list\"><li>Go to the <strong>Control Panel &gt; Advanced Mode &gt; Terminal &amp; SNMP<\/strong>.<\/li><li>Click the <em>Enable SSH Service<\/em> option under the <strong>Terminal<\/strong> tab. Change your default SSH port, if desired.<\/li><\/ul>\n\n\n\n<p><strong>NOTE:<\/strong> Synology restricts SSH\/Telnet connections to members of the <strong>Administrators<\/strong> group on any particular Synology device. If you don\u2019t already have a <code>git<\/code>-access-specific user with administrator privileges, it is a good time to create one. From here on out, if I need to refer to this specific user, I will do so with <code>&lt;git-username&gt;<\/code>. Just replace <code>&lt;git-username&gt;<\/code> with your user when following these instructions.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Go to the <strong>Control Panel &gt; User<\/strong> section and create the <code>&lt;git-username&gt;<\/code> user.<\/li><li>Add this new user to the <em>Administrators<\/em> group. Depending on your repository location, you may need to add <em>Read\/Write<\/em> permissions for the <code>root<\/code> part of the NAS filesystem inside <code>\/volume1<\/code>.<\/li><li>Go to the <strong>Main Menu &gt; Git Server<\/strong> and click the <em>Allow Access<\/em> check box for <code>&lt;git-username&gt;<\/code>.<\/li><\/ul>\n\n\n\n<p><strong>NOTE:<\/strong> From here on out, I will be using the command line (and connecting via SSH instead of the Synology browser-based front end). In order to follow along, you will need the IP address for your Synology NAS on the network. I will refer to that IP as <code>&lt;nas-address><\/code> where necessary. Just replace <code>&lt;nas-address><\/code> with your server\u2019s IP address when following these instructions. If you are using a Windows machine, you may need a terminal emulator to continue.<\/p>\n\n\n\n<p>On the NAS server, log in as <code>admin<\/code> and configure SSH to streamline repository access in the future. If you get an error about the \u201chomes\u201d directory not existing (or something similar):<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>$ ssh admin@&lt;nas-address>\n$ sudo -i\n\n$ cd \/volume1\/homes\/&lt;git-username>\/\n$ mkdir .ssh\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>On the local machine, copy your public key to the newly-made <code>.ssh<\/code> folder on the NAS:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">1<code>$ scp ~\/.ssh\/id_rsa.pub admin@&lt;nas-address&gt;:\/volume1\/homes\/&lt;git-username&gt;\/.ssh\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Back on the NAS server, use the public key you transferred over to act as the lone authorized user in the <code>&lt;git-username&gt;<\/code> profile and set file permissions accordingly:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>$ ssh admin@&lt;nas-address>\n$ sudo -i\n\n$ cd \/volume1\/homes\/&lt;git-username>\/.ssh\n$ mv id_rsa.pub authorized_keys\n\n$ cd \/volume1\/homes\/\n$ chown -R &lt;git-username>:administrators &lt;git-username>\/.ssh\n$ chmod 750 &lt;git-username>\n$ chmod 700 &lt;git-username>\/.ssh\n$ chmod 600 &lt;git-username>\/.ssh\/authorized_keys\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"creating-a-repository\">Creating a Repository<\/h4>\n\n\n\n<p>Following along with the assumption that the <code>&lt;git-username&gt;<\/code> user will access git repositories either in <code>\/volume1\/root\/<\/code> or just <code>\/volume1\/<\/code> itself, we need to actually initialize the repository now. I am assuming <code>\/volume1\/git\/&lt;dummy-name.git&gt;<\/code> is the target repository; make changes to the target path or repository name as required. <em>You will have to do this step for every individual repository that is hosted on the server.<\/em><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>$ # SSH into the NAS server as &lt;git-username>\n$ ssh &lt;git-username>@&lt;nas-address>\n\n$ # Navigate to your prospective repository location and initialize a new, shared repository\n$ mkdir \/volume1\/git\n$ cd \/volume1\/git\n$ git init --bare --shared &lt;dummy-name.git>\n\n$ # It also may be a good idea to open up the permissions for the git repository, just in case\n$ chmod -R 766 &lt;dummy-name.git>\n\n$ # Finally, update the pack information for the git service running on the NAS\n$ cd &lt;dummy-name.git>\n$ git update-server-info\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"cloning-a-repository\">Cloning a Repository<\/h4>\n\n\n\n<p>Try this command in a folder on your local machine:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>$ git clone ssh:\/\/&lt;git-username>@&lt;nas-address>\/volume1\/git\/&lt;dummy-name.git>\n<\/code><\/pre>\n\n\n\n<p>You can now push to and pull from the remote repository on your local server!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Go to the Control Panel &gt; Advanced Mode &gt; Terminal &amp; SNMP. Click the Enable SSH Service option under the Terminal tab. Change your default SSH port, if desired. NOTE: Synology restricts SSH\/Telnet connections to members of the Administrators group [&hellip;]<\/p>\n<div class=\"link-more\"><a href=\"https:\/\/amsd.go.ro\/wordpress\/?p=244#more-244\" class=\"more-link\">Continue reading &#10142; <span class=\"screen-reader-text\">Setting up SSH Access on Synology storage and Create New Git Repository<\/span><\/a><\/div>","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[20,11,12],"class_list":["post-244","post","type-post","status-publish","format-standard","hentry","category-technology","tag-ps_19","tag-ps_57","tag-ps_17"],"_links":{"self":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/244","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=244"}],"version-history":[{"count":6,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/244\/revisions"}],"predecessor-version":[{"id":252,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/244\/revisions\/252"}],"wp:attachment":[{"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/amsd.go.ro\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}