Wiki source code of Remote Access Gateway

Version 2.7 by Xiaoling on 2022/05/12 14:47

Hide last authors
Xiaoling 1.2 1 **Contents:**
2
Xiaoling 1.1 3 {{toc/}}
4
5
Xiaoling 1.2 6 = 1. Use Remote.it service =
Xiaoling 1.1 7
Xiaoling 1.2 8 Remote.it for remote access is available in the latest Dragino firmware for gateway. For security concern, the remote.it only available base on end user demand.
Xiaoling 1.1 9
Xiaoling 1.3 10 (% class="mark" %)**Important Notice:**
Xiaoling 1.1 11
Xiaoling 1.3 12 * (% class="mark" %)**Remote.it access will give full control of your device to remote support.**
13 * (% class="mark" %)**The Remote.it allow Dragino Support to remote access to the device, If user want to access himself, it need to sign up for an remote.it account.**
Xiaoling 1.1 14
Xiaoling 1.2 15 For how to use remoteit, please see : [[Remoteit user instruction for Dragino Gateway>>url:https://www.dragino.com/downloads/index.php?dir=LoRa_Gateway/&file=Dragino-Remoteit_User_Manual.pdf]].
Xiaoling 1.1 16
17
Xiaoling 1.2 18 = 2. RSSH Introduction =
Xiaoling 1.1 19
Xiaoling 1.2 20 Reverse SSH for remote access is available in the latest Dragino firmware for gateway. For security concern, the RSSH only available base on end user demand.
Xiaoling 1.1 21
Xiaoling 1.3 22 (% class="mark" %)**Important Notice:**
Xiaoling 1.1 23
Xiaoling 1.3 24 * (% class="mark" %)**RSSH access will give full control of your device to remote support. Please remove sensitivity info before perform this**
25 * (% class="mark" %)**This RSSH allow Dragino Support to remote access to the device, If user want to access himself, he need to set up the RSSH server himself.**
Xiaoling 1.1 26
Xiaoling 1.2 27 Below gateway support reverse SSH access:
Xiaoling 1.1 28
Xiaoling 1.2 29 * Firmware Version > LG02_LG08-5.3.1580178039 [[Firmware Download>>url:http://www.dragino.com/downloads/index.php?dir=LoRa_Gateway/LPS8/Firmware/Release/]]
30 * LG01N, OLG01N (Note: LG01-P LG01-S doesn't support)
31 * LG02, OLG02
32 * LG308, DLOS8
33 * LPS8
34 * LIG16
35 * MS14 series if installed with the same firmware.
Xiaoling 1.1 36
Xiaoling 1.2 37 == 2.1 For Firmware Version lower than lgw~-~-build-v5.4.1616478814-20210323-1355 ==
38
39 === 2.1.1 End User Guide to use SSH access ===
40
41 Go to this the Reverse SSH page as below:
42
43 [[image:https://wiki.dragino.com/images/thumb/5/55/RSSH_Menu2.png/500px-RSSH_Menu2.png||height="256" width="500"]]
44
45 Get the RSSH configure page
46
47
48 [[image:https://wiki.dragino.com/images/thumb/7/78/RSSH_Menu3.png/500px-RSSH_Menu3.png||height="313" width="500"]]
49
50 Connection OK.
51
Xiaoling 2.2 52 * (% class="mark" %)**Login ID**(%%): Input (% class="mark" %)**sshuser**
53 * (% class="mark" %)**Host Address**(%%): Input(% class="mark" %)** support.dragino.com**
54 * (% class="mark" %)**Host Port**(%%): Please email to support @ dragino.com to get a valid host port.
55 * (% class="mark" %)**Connect at Startupt**(%%): Choose to enable connect once device is powered.
56 * (% class="mark" %)**Network Keys:**(%%)Click the Generate keys to generate the keys and download / mail it to Dragino support so Dragino can prepare the remote access to
Xiaoling 1.2 57
Xiaoling 2.2 58 (((
Xiaoling 1.2 59 After doing above, please download and mail the public keys to Dragino support and wait for our mail for the valid host port. Input the valid host port got from our support and click connect so we can remote access to your gateway.
Xiaoling 2.2 60 )))
Xiaoling 1.2 61
62
63 === 2.1.2 How to Ser up a Reverse SSH access ===
64
65 Advance administrator can config a SSH server to provide support their end user themselves. Instruction is as below:
66
67 1. Prepare a Linux server with public IP. The gateways need to be able to create SSH connection to this server. We recommend to use a server that performs no other function than to support the RSSH access, and to have no additional accounts active, and no access from the Internet that uses ID/password authentication.
Xiaoling 2.3 68 1. In the gateway settings, The (% class="mark" %)**Login ID**(%%) will be the SSH user for this server and the (% class="mark" %)**Host Address**(%%) is the server address.
Xiaoling 1.2 69 1. Ask your end user to send you the key generate in the gateway and put them in /home/<Login ID>/.ssh/authorized_key file.
70 1. Give a free port to the user and ask them to configure RSSH page in the gateway.
71 1. In your server or other machine, you will able to access to the end user device by below command:
72
Xiaoling 2.5 73 (% class="box" %)
74 (((
75 $ ssh   -p <End User Host Port>   root@<Host Address>
76 )))
Xiaoling 1.2 77
Xiaoling 2.5 78 (((
Xiaoling 2.3 79 (% class="mark" %)**Remote RSSH Access allow the gateway to connect to SSH server as well. This will create risk to the RSSH server. Please make sure the account use for Gateway Access has the lowest access right.**
Xiaoling 2.5 80 )))
Xiaoling 1.2 81
Xiaoling 2.3 82
Xiaoling 1.2 83 ==== 2.1.2.1 Note for set up RSSH server ====
84
85 * If gateway reboot or the connection is incidentely close by end node. The port in SSH server will still be occupy for a long time. Administrator can use below commands to release the port.
86
Xiaoling 2.4 87 (% class="box" %)
88 (((
89 [root@iZt4n22vqvm7ajogrfiif6Z ~~]# lsof -i :9102 ~-~-> check the port 9102 process status (change 9102 to the actually port for your gateway.
90 COMMAND   PID    USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
91 sshd    21430 sshuser   15u  IPv4 47567059      0t0  TCP localhost:bacula-fd (LISTEN)
92 [root@iZt4n22vqvm7ajogrfiif6Z ~~]# kill 21430   ~-~-> Kill PID of this process.
93 [root@iZt4n22vqvm7ajogrfiif6Z ~~]# lsof -i :9102        
94 [root@iZt4n22vqvm7ajogrfiif6Z ~~]#
95 )))
Xiaoling 1.2 96
97 == 2.2 For Firmware Version higher than lgw~-~-build-v5.4.1618196981-20210412-1111 ==
98
99 Below gateway support reverse SSH access:
100
Xiaoling 2.5 101 (% class="box" %)
102 (((
103 Firmware Version >lgw~-~-build-v5.4.1618196981-20210412-1111 Firmware Download
Xiaoling 1.2 104 LG01N, OLG01N (Note: LG01-P LG01-S doesn't support)
105 LG02, OLG02
106 LG308, DLOS8
107 LPS8
108 LIG16
Xiaoling 2.5 109 )))
Xiaoling 1.2 110
111 === 2.2.1 End User Guide to use SSH access ===
112
113 ==== 2.2.1.1 Install the SSH service for server ====
114
115 ===== 2.2.1.1.1 Step 1:Download the SSH service code =====
116
117 1).git clone [[https:~~/~~/github.com/dragino/rssh-server.git>>url:https://github.com/dragino/rssh-server.git]] rssh-server
118
119 [[image:https://wiki.dragino.com/images/thumb/d/d0/Git_clone.png/500px-Git_clone.png||height="80" width="500"]]
120
121 git clone rssh-server
122
Xiaoling 2.5 123
Xiaoling 1.2 124 2).cd rssh-server; sudo make ~-~--> to Generate the execute file:rssh_serv
125
126 [[image:https://wiki.dragino.com/images/thumb/e/e3/Generate_the_execute_file.png/500px-Generate_the_execute_file.png||height="103" width="500"]]
127
128 Generate the execute file
129
130 **Debug** :
131
Xiaoling 2.5 132 (% class="box" %)
133 (((
134 if you git fail.  ~-~->    (% class="mark" %)**sudo: git: command not found.**(%%)
135 please install git.  ~-~->    (% class="mark" %)**yum install git -y  or  apt-get install git -y. **
136 )))
Xiaoling 1.2 137
Xiaoling 2.5 138 (% class="box" %)
139 (((
140 if you make error 127,it** (% class="mark" %)lack of gcc.(%%)**
141 please install gcc.    ~-~->(% class="mark" %)**yum install gcc.**
142 )))
Xiaoling 1.2 143
144 [[image:https://wiki.dragino.com/images/d/d7/Lack_of_gcc.png||height="174" width="434"]]
145
146 lack of gcc
147
Xiaoling 2.5 148 (% class="box" %)
149 (((
150 if you make a fatal error : sqlite3.h,it (% class="mark" %)**lack of sqlite3.**(%%)
151 please insatell **sqlite3**.
152 )))
Xiaoling 1.2 153
154 [[image:https://wiki.dragino.com/images/thumb/9/93/Lack_of_sqlite3.png/500px-Lack_of_sqlite3.png||height="137" width="500"]]
155
156 lack of sqlite3
157
158 How to install Sqlit3
159
Xiaoling 2.5 160 (% class="box" %)
161 (((
162 Step1:Download the SQLit3 installation package
163 sudo wget [[https:~~/~~/www.sqlite.org/2021/sqlite-autoconf-3350400.tar.gz>>url:https://www.sqlite.org/2021/sqlite-autoconf-3350400.tar.gz]]
164 Step2:tar the SQLit3 installation package
Xiaoling 1.2 165 sudo tar -zxvf sqlite-autoconf-3350300.tar.gz
Xiaoling 2.5 166 Step3:Generate the makefile
Xiaoling 1.2 167 cd sqlite-autoconf-3350300/;./configure
Xiaoling 2.5 168 Step4:Compile makefile
Xiaoling 1.2 169 sudo make
Xiaoling 2.5 170 Step5:Install makefile
Xiaoling 1.2 171 sudo make install
Xiaoling 2.5 172 Check:
173 cd /usr/local/bin;ls -al                             ~-~->    Check to see if there is a file for sqlite3
174 cd sqlite-autoconf-3350300/;./sqlite3 test.db        ~-~->    Test whether the sqlite3 was installed successfully
175 debug:
Xiaoling 1.2 176 If you get the imformation that is SQLite header and source version mismatch, when you execute./sqlite3 test.db.
177 Please execute the command /sbin/ldconfig.
178 After that execute the command ./sqlite3 test.db again.
Xiaoling 2.5 179 )))
Xiaoling 1.2 180
Xiaoling 2.5 181
Xiaoling 1.2 182 ===== 2.2.1.1.2 Step 2 :Install and run the RSS service =====
183
184 1):intall database for /var/rsshdb.sqlite3 and Server development port for 3721(The default is 3721)
185
186 user must enter the root account and run the following commands
187
Xiaoling 2.5 188 (% class="box" %)
189 (((
190 $ ./create_sqlite3_db.sh
191 $ ./rssh_serv -p  3721 2>&1 &
192 $ ps -ef | grep rssh_serv check 3721 port
193 )))
Xiaoling 1.2 194
195 [[image:https://wiki.dragino.com/images/thumb/c/cb/Intall_database_and_server_development_port.png/500px-Intall_database_and_server_development_port.png||height="70" width="500"]]
196
197 intall database and server development port
198
199 **Debug:**
200
Xiaoling 2.5 201 (% class="box" %)
202 (((
203 Check /var/rsshdb.sqlite3 ~-~->(% class="mark" %)** ls /var/rsshdb.sqlite3**(%%)
204 Check ls /var/rsshdb.sqlite3 ~-~-> (% class="mark" %)**sudo chmod 777 rssh_serv**
205 )))
Xiaoling 1.2 206
Xiaoling 2.5 207 (% class="box" %)
208 (((
209 if** fail to open dpvlry or to bind to it**
210 please kill rssh_serv,and run (% class="mark" %)** ./rssh_serv -p  3721 2>&1 &** (%%) again
211 )))
Xiaoling 1.2 212
Xiaoling 2.5 213
Xiaoling 1.2 214 ===== 2.2.1.1.3 Step 3 :Create a minimal SSH user (reverse SSH proxy for the gateway) =====
215
Xiaoling 2.5 216 1):(% class="mark" %)**sudo useradd XXXXX**(%%) (custom user name)
Xiaoling 1.2 217
Xiaoling 2.5 218 2):(% class="mark" %)**sudo passwd xxxxxx**
Xiaoling 1.2 219
Xiaoling 2.5 220 3):(% class="mark" %)**cp /bin/bash /bin/rbash**
Xiaoling 1.2 221
Xiaoling 2.5 222 4):(% class="mark" %)**sudo nano /etc/passwd**(%%) ~-~-> Change /bin/bash to /bin/rbash
Xiaoling 1.2 223
Xiaoling 2.5 224 5):(% class="mark" %)**sudo nano /home/xxxxx/.bashrc**(%%) **empty it,and input export PATH=$HOME/bin**
Xiaoling 1.2 225
Xiaoling 2.5 226 6):(% class="mark" %)**sudo nano /home/xxxxx/.bash_profile**(%%) **empty it,and input export PATH=$HOME/bin**
Xiaoling 1.2 227
228 **Now user "XXXXX" is the user with limited permissions of the current system**
229
Xiaoling 2.5 230
Xiaoling 1.2 231 === 2.2.2 How does user get the gateway to connect to a user's private server ===
232
233 ===== 2.2.2.1 Step1: Come bace the gateway web UI for get the gateway Public key =====
234
Xiaoling 2.5 235 1)in the system ~-~-> (% class="mark" %)**Remote Mgmt/span>**
Xiaoling 1.2 236
237 [[image:https://wiki.dragino.com/images/thumb/8/8f/Remote_Mgmt.png/500px-Remote_Mgmt.png||height="367" width="500"]]
238
239 Remote Mgmt
240
Xiaoling 2.6 241
Xiaoling 1.2 242 ===== 2.2.2.2 Step2: Authorization server =====
243
244 copy the Gateway Publickey into user's private server "/home/XXXXX/.ssh/authorized_keys" file.
245
246 [[image:https://wiki.dragino.com/images/thumb/4/49/Publickey.png/500px-Publickey.png||height="81" width="500"]]
247
248 Publickey
249
Xiaoling 2.6 250
Xiaoling 1.2 251 ===== 2.2.2.3 Step3: connecte private server =====
252
253 in the gateway web UI
254
255 [[image:https://wiki.dragino.com/images/thumb/0/04/Gateway_web_UI.png/500px-Gateway_web_UI.png||height="389" width="500"]]
256
257 gateway web UI
258
Xiaoling 2.6 259 (% class="box" %)
260 (((
261 (% class="mark" %)**Connection Type **(%%) : If user's least privileged user with private server uses a password, select (% class="mark" %)**Public Key**(%%)
262 **Note:if user's least privileged user no uses a password,choose from both is fine**
263 (% class="mark" %)**Login ID**(%%)             : Input user name "eg : "XXXXX"
264 (% class="mark" %)**Host Address**(%%)         : Input user's private server address
265 (% class="mark" %)**Connect at Startupt**(%%): Choose to enable connect once device is powered.
Xiaoling 1.2 266 Click Save and then Connect
Xiaoling 2.6 267 )))
Xiaoling 1.2 268
Xiaoling 2.7 269
Xiaoling 1.2 270 ===== 2.2.2.4 Step 4 :Cheak is fine =====
271
272 Rssh Host connection Ok
273
274 [[image:https://wiki.dragino.com/images/thumb/6/6f/Rssh_Host_connection_Ok.png/500px-Rssh_Host_connection_Ok.png||height="225" width="500"]]
275
276 Rssh Host connection Ok
277
Xiaoling 2.7 278
Xiaoling 1.2 279 user can use common ps | grep ssh to check it in the gateway.
280
Xiaoling 2.7 281 [[image:https://wiki.dragino.com/images/thumb/a/ad/Check_the_gateway.png/500px-Check_the_gateway.png]]
Xiaoling 1.2 282
283 Check the gateway
284
285
286 ===== 2.2.2.5 Step5:Create an authorization key file =====
287
288 1):sudo mkdir /home/xxxxx/.ssh; sudo touch /home/xxxxx/.ssh/authorizedkey
289
290 **Debug:**
291
Xiaoling 2.7 292 (% class="box" %)
293 (((
294 check: sudo ls /home/xxxxx/.ssh/authorizedkey
295 )))
Xiaoling 1.2 296
297 === 2.2.3 How to Ser up a Reverse SSH access ===
298
299 ==== 2.2.3.1 Step1: Log into the server system ====
300
301 [[image:https://wiki.dragino.com/images/thumb/2/26/Loging_server.png/500px-Loging_server.png||height="69" width="500"]]
302
303 Loging server
304
305 ==== 2.2.3.2 Step2:access the gateway ====
306
307 $ cd rssh-server/
308
309
310 Check the gateway linking to the server $ ./connect-gw.sh -l
311
312 [[image:https://wiki.dragino.com/images/thumb/e/ee/Check_gateway_link_server.png/500px-Check_gateway_link_server.png||height="157" width="500"]]
313
314 Check the gateway linking to the server
315
316
317 access the gateway $ ./connect-gw.sh <GWID>
318
319 [[image:https://wiki.dragino.com/images/thumb/b/b7/Reverse_ssh_access_the_gateway1.png/500px-Reverse_ssh_access_the_gateway1.png||height="230" width="500"]]
320
321 reverse ssh access the gateway