How do I fix "Error opening terminal: unknown." on Ubuntu server?
Solution 1
Webmin terminal is not interactive yet. In-fact, it's a command line interface.
You can read more about it, we discussed it quite a lot.
It's in our todo to make it interactive.
Solution 2
Try to run /bin/bash, I think it will allocate pseudo tty
Also try:
TERM=linux
then run nano
Solution 3
I encountered this problem when I was trying to edit files inside the initramfs. This was the only thread I found so instead of hunting for another fix, I wrote a python script to make a simple text editor that works inside the initramfs (and other feature poor terminals)
It's pretty simple, only displays one line at a time so you press up and down to change lines and left and right to move the cursor and enter to save. Nothing fancy, but it seems to work okay for quick edits.
It requires only the readchar module: python3 -m pip install readchar
#!/usr/bin/python3
#Edit a text file inside the initramfs (when other text editors don't work)
'''Compile with:
libgcc=$(find /lib -name libgcc_s.so.1 | head -n 1)
libutil=$(ldd /usr/bin/python3 | grep libutil | cut -d ' ' -f 3)
pyinstaller --onefile editfile.py --add-data="$libgcc:." --add-data="$libutil:." --hidden-import readchar
'''
import shutil, sys, readchar
'''
Allow user to edit a line of text complete with support for line wraps and a cursor | you can move back and forth with the arrow keys.
lines = initial text supplied to edit
prompt= Decoration presented before the text (not editable and not returned)
'''
def text_editor(lines=[], prompt=''):
term_width = shutil.get_terminal_size()[0] - 1
line_num = 0
if type(lines) in (list, tuple):
multiline=True
else:
multiline=False
lines=[lines]
text = list(lines[line_num])
ptr = len(text)
prompt = list(prompt)
space = [' ']
c = 0
while True:
if ptr and ptr > len(text):
ptr = len(text)
copy = text.copy()
if ptr < len(text):
copy.insert(ptr,'|')
copy = list(str(line_num)) + space + prompt + copy
#Line wraps support:
if len(copy) > term_width:
cut = len(copy) + 3 - term_width
if ptr > len(copy) / 2:
copy = ['<']*3 + copy[cut:]
else:
copy = copy[:-cut] + ['>']*3
print('\r'*term_width+''.join(copy), end=' '*(term_width-len(copy)), flush=True)
if c in (53,54):
#Page up/down bug
c = readchar.readkey()
if c == '~':
continue
else:
c = readchar.readkey()
if len(c) > 1:
#Control Character
c = ord(c[-1])
#Save current line on line change
if c in (53, 54, 65, 66):
lines[line_num] = ''.join(text)
if c == 65: #Up
line_num -= 1
elif c == 66: #Down
line_num += 1
elif c == 68: #Left
ptr -= 1
elif c == 67: #Right
ptr += 1
elif c == 54: #PgDn
line_num += 10
elif c == 53: #PgUp
line_num -= 10
elif c == 70: #End
ptr = len(text)
elif c == 72: #Home
ptr = 0
else:
print("\nUnknown control character:", c)
print("Press ctrl-c to quit.")
continue
if ptr < 0:
ptr = 0
if ptr > len(text):
ptr = len(text)
#Check if line changed
if c in (53, 54, 65, 66):
if multiline == False:
line_num = 0
continue
if line_num < 0:
line_num = 0
while line_num > len(lines) - 1:
lines.append('')
text = list(lines[line_num])
else:
num = ord(c)
if num in (13, 10): #Enter
print()
lines[line_num] = ''.join(text)
if multiline:
return lines
else:
return lines[0]
elif num == 127: #Backspace
if text:
text.pop(ptr-1)
ptr -=1
elif num == 3: #Ctrl-C
sys.exit(1)
else:
text.insert(ptr, c)
ptr += 1
#Main
if len(sys.argv) == 1:
print("Usage: ./editfile <filename>")
sys.exit(1)
f = open(sys.argv[1], 'r')
strings = f.read().split('\n')
f.close()
strings = text_editor(strings)
#Trim empty lines on end
for x in range(len(strings) -1,0, -1):
if len(strings[x]):
break
else:
strings.pop(-1)
f = open(sys.argv[1], 'w')
f.write('\n'.join(strings)+'\n')
Solution 4
I had the same problem and it was solved in the following way:
sudo apt-get install rxvt-unicode
Related videos on Youtube
Stuperfied
Updated on September 18, 2022Comments
-
Stuperfied almost 2 years
I searched and found similar questions but none were specific enough or solved my issue. An example would be this question Starting remote script/terminal based programs through ssh gives error (Error opening terminal: unknown.) which I am not using
ssh
so-t
will not help.
Running webmin, has been fine for months and now I get this error.
Basically when I type nano or vi into terminal, I get the error "Error opening terminal: unknown."
[user@host ~]# nano Error opening terminal: unknown. [user@host ~]# lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04.3 LTS Release: 16.04 Codename: xenial [user@host ~]# nano Error opening terminal: unknown. [user@host ~]#
How do I fix "Error opening terminal: unknown." on Ubuntu 16.04.3 LTS running webmin?
New information:
- When I try running vi or nano directly on the server instead of using webmin or ssh to remote in, it works. Could this just be a problem with webmin?
- When I examine the environment variables it say's
TERM=linux
which is consistent with my other server which is running all the same software.
-
Stuperfied over 5 years
[user@host ~]# /bin/bash [user@host ~]# nano Error opening terminal: unknown. [user@host ~]# TERM=linux [user@host ~]# nano Error opening terminal: unknown. [user@host ~]# export TERM=linux [user@host ~]# nano Error opening terminal: unknown. [user@host ~]#
-
LeonidMew over 5 yearsI have no more ideas, looks like webmin not being able to run ncurses based applications
-
davidbaumann over 4 yearsAny explanation about this?
-
sdbbs over 2 years@davidbaumann - same; so I looked for
*rxvt*
, and there is a directory/usr/share/terminfo
or/etc/terminfo/
with files likerxvt-256color
and so on, and it turns out, it is installed byncurses-bin_6.0+20160213-1ubuntu1_amd64
, and that package likely gets pulled in byrxvt-unicode