Page 1 of 1

Annoying issues with SSH'ing to NAS

Posted: Mon Apr 12, 2021 8:15 pm
by afjochnick
I am using my NAS as a server, i.e. i run tomcat and other things on it and frequently need to ssh in and do stuff.


3 things that really degrade my experience are:

1. i cannot do any shortcuts, for example "cdl" as an alias for something, because edits to bash_profile is prevented.

2. In the latest versions, i get some "menu" when i SSH in and i have to press "Q" and "Y" every single time.

3. The command history is cleared on every reboot, i.e. when i press arrow up, my commands are not remembered.

Is there any way to sort out any of these things?

Re: Annoying issues with SSH'ing to NAS

Posted: Mon Apr 12, 2021 9:21 pm
by dolbyman
2. Can be deactivted in GUI

Control Panel > System > General Settings > Console Management > Enable Console Management

Re: Annoying issues with SSH'ing to NAS

Posted: Tue Apr 13, 2021 2:27 am
by OneCD
afjochnick wrote: Mon Apr 12, 2021 8:15 pm 1. i cannot do any shortcuts, for example "cdl" as an alias for something, because edits to bash_profile is prevented.
Add your aliases to [/etc/profile] instead. Changes to this file do not persist between reboots, so be prepared to add them again after each startup. ;)
afjochnick wrote: Mon Apr 12, 2021 8:15 pm 3. The command history is cleared on every reboot, i.e. when i press arrow up, my commands are not remembered.
Correct, the bash history is not retained, because the history file is also not stored in a persistent location. Same as [/etc/profile].

If you'd like to keep your history between power-on sessions, you'll need to move [/root/.bash_history] to a persistent location, and restore it into [/root] after each reboot (suggest creating a symlink in [/root] pointing to your persistent file).

Re: Annoying issues with SSH'ing to NAS

Posted: Mon Apr 19, 2021 3:10 pm
by afjochnick
HI both of you thanks for responding.

Dolbyman, thanks had missed that, that's something at least..

OneCD, thanks i knew about those "workarounds", that's kind of what i meant with "prevented". I power boot every day. My TS259B Mini sounds like a bloody jet engine even when it's idle (i created another thread about that...), and its in our apartment. Therefor my wife has kindly requested that we power it down every night.
It's really frustrating and i will checkout their main competitor to see if it's more silent, and if it's possible to conduct sane terminal activities there.

Re: Annoying issues with SSH'ing to NAS

Posted: Fri Apr 23, 2021 4:58 pm
by Mousetick
1. Create a regular user.
2. Make that user a member of administrators group.
3. Allow that user to login via SSH (Control Panel > Network & File Services > Telnet / SSH)

Now this user's home directory is stored on persistent storage and you can customize its shell as you see fit and not lose your customizations between reboots.

If you need superuser privileges, the setup process is a little more involved, but it can be one-time set-and-forget thing. The goal is to use sudo which is preinstalled on QNAP but its default configuration is "hard-coded" in firmware. So a workaround is necessary.

The hardcoded configuration is located at /usr/etc/sudoers.

4. Copy /usr/etc/sudoers to /etc/config. This directory's contents are stored on persistent HD storage.
5. Edit /etc/config/sudoers and add your user.

Now the tricky part:

6. Make a symbolic link from /etc/config/sudoers to /usr/etc/sudoers, so that sudo uses your modified copy of sudoers:

Code: Select all

$ ls -l /usr/etc/sudoers
lrwxrwxrwx 1 admin administrators 19 Apr 22 23:59 /usr/etc/sudoers -> /etc/config/sudoers
The link will be lost after each reboot, so you either need to recreate it manually each time (while logged in as admin user), or you can use a shell script to recreate it automatically at boot time, using the autorun mechanism (Control Panel > System > Hardware > General > Run user defined processes during startup).

For setting up the autorun mechanism, I recommend @OneCD's excellent create-autorun script which makes it very easy and foolproof.

Re: Annoying issues with SSH'ing to NAS

Posted: Sat Jan 07, 2023 12:50 am
by plutoniumhead
Based on the suggestion by @Mousetick I believe I figured out a way to make superuser privileges survive a reboot.

Start by following steps 1–3 above:
1. Create a regular user.
2. Make that user a member of administrators group.
3. Allow that user to login via SSH (Control Panel > Network & File Services > Telnet / SSH)

Create an amendment to the sudoers file:
4. Launch a text editor and create a file; in this example I used vi but it's not required like it is to edit the master sudoers file. I prefer nano but it is not installed by default:

Code: Select all

vi /etc/config/sudoers
Add the following line containing the username (or one user per line):

Code: Select all

<USERNAME> ALL=(ALL) ALL
Then save and quit.

5. The following is a one-liner that will check for the existence of the sudoers inclusive directory, create it if it's missing, then create a symlink to the file you created in the previous step:

Code: Select all

find /usr/etc/sudoers.d || mkdir /usr/etc/sudoers.d && ln -s /etc/config/sudoers /usr/etc/sudoers.d/sudoers
Users you've added to the sudoers file will now be able to invoke "sudo -i" to become root. The symlink will not survive a reboot, so here's how to work around that:

To add the one-liner command from step 5 to the autorun.sh script (*these steps might be slightly different depending on your system):

6. Mount the config ramblock:

Code: Select all

mount -t ext2 /dev/mtdblock5 /tmp/config
7. Open the script in a text editor…

Code: Select all

vi /tmp/config/autorun.sh
…add the one-liner command…

Code: Select all

find /usr/etc/sudoers.d || mkdir /usr/etc/sudoers.d && ln -s /etc/config/sudoers /usr/etc/sudoers.d/sudoers
…then save and quit. Note that if you haven't previously created this autorun script, you will need make this file executable:

Code: Select all

chmod +x /tmp/config/autorun.sh
8. Lastly, unmount the config ramblock:

Code: Select all

umount /tmp/config
For what it's worth, I just tested this and it survived a reboot.

Re: Annoying issues with SSH'ing to NAS

Posted: Sat Jan 07, 2023 1:08 am
by dolbyman
closed to prevent further necroposting