----------------------------------- Using telnet/ssh Terminal emulators ----------------------------------- - Ian! D. Allen idallen@idallen.ca This section will assist you in making ssh or telnet terminal connections to a Unix/Linux system work properly, especially if you connect to Unix from machines running Microsoft operating systems. Some (all?) versions of Microsoft's telnet client do not pass on information about the connection to the remote Unix/Linux system, leading to problems. Warning! If you do not follow the basic rules in this document, you may lose data on the Unix machine if you try to edit using a full-screen editor (such as vi)! You need to configure your ssh or telnet client and the remote Unix terminal so that full-screen programs such as vi know the size of your telnet window and the type of terminal emulator you are using. This section should help solve problems and errors such as the following: your backspace key shows: ^H^H^H^H^H^ -or- ^?^?^?^?^?^? ex: unknown is not a recognized terminal type. ex: linux is not a recognized terminal type. ex: ANSI is not a recognized terminal type. ex: Visual mode requires more cursor capability than the terminal provides. WARNING: terminal is not fully functional Terminal entry not found in terminfo 'linux' not known. Available builtin terminals are: [...list...] defaulting to 'ansi' If you get errors similar to the above, or if vi is not redrawing the screen correctly, read on. After reading this document, you will understand the following: $ stty -a $ /usr/bin/X11/resize $ TERM=vt100 $ export TERM $ stty erase '^H' $ stty erase '^?' ----------------------- VI/VIM Screen Size Test ----------------------- Use this test to make sure that your screen is configured correctly. Use telnet or ssh to connect to the Unix/Linux system on which you wish to work. Enter the vi/vim text editor. Try these two tests: Test 1: Line Count Push the ESCAPE key to return to VI command mode. Type a colon : character to move the cursor to the bottom of the screen. Is the colon on the very last line of the window, with no blank line under it? If not, do not use the editor until you fix your terminal size. The cursor must move to the last line for vi or vim to work properly. See below for how to use the resize command to fix your terminal. Test 2: Backspace Key Push the ESCAPE key to return to VI command mode. Enter the letter i to go into INPUT MODE in the vim editor. Type the word test followed by four backspaces. (Push the backspace key, located above the RETURN key, not the back-arrow key or the DEL key.) If the word does not get erased and you see this on your screen: test^H^H^H^H -or this- test^?^?^?^? You need to set your terminal erase character at login. See below for how to set the terminal erase character. After this test, push the ESCAPE key then type :q! to exit from vi without saving changes. ---------------- Some Basic Rules ---------------- You must check these things every time you connect to Unix: 1. If you are using a Windows telnet client (don't use telnet - use SSH), make sure your telnet window is dragged out to full size when you use it. You will know it is full size if both the vertical and horizontal scroll bars are gone. Drag the bottom right-hand corner of the telnet window outward until both scroll bars are gone. On Windows 95, you must do this every time you start up telnet. (Only Microsoft knows why.) 2. Make sure Unix knows the size of your terminal window after you log in. (See below.) 3. Make sure Unix recognizes your terminal type. (See below.) 4. Make sure Unix recognizes your Backspace key. (See below.) When you learn how to create and edit a .bash_profile file in your $HOME directory, you can automate much of the above process so that the correct environment is set up each time you log in. ---------------------- When logged in to Unix ---------------------- Once you start ssh or telnet and connect to Unix/Linux, avoid changing the size of your terminal window or the type of terminal emulation you are using. If you change these things, Unix may not know about the changes, and your session will not display correctly. On the Unix/Linux side of your ssh or telnet connection, once you are logged in, you have to make sure of these things: 1. The number of lines set in your terminal matches the number of lines that Unix thinks you are using. 2. Your terminal type (set as you log in) is recognized on Unix. 3. Your Backspace key is recognized on Unix. ------------------------------------------- Setting the correct number of lines on Unix ------------------------------------------- Once you are connected to Unix and have logged in, you need to ensure that Unix knows the size of the ssh or telnet terminal window you are using. You may need to do the commands below every time you connect to Unix. Once you learn how to create a .bash_profile file, you can put these commands into that file for automatic execution every time you log in. Use the Unix resize command on Unix to make Unix know the size of your ssh or telnet window. If just typing resize at the Unix prompt doesn't work (if you get "command not found"), you'll have to type the full absolute Unix pathname of the resize command, /usr/bin/X11/resize, so use whichever command line works: $ resize -or- $ /usr/bin/X11/resize Use either of the above Unix command lines. (It doesn't hurt to type it more than once; but, only once is necessary.) Note the upper-case letter X followed by the number eleven in the full pathname, and remember to use forward slashes and not backslashes. What you should see as output after you type the command into Unix is something similar to the following: $ resize COLUMNS=80; LINES=24; export COLUMNS LINES; The number of LINES= may differ for your partcular terminal window. If you do not see this kind of output using either of the above pathnames, check your typing, then consult a lab monitor or instructor. To use successfully full-screen commands such as vi on Unix, the number of LINES shown in the output of resize must match the Buffer Size given in the Windows ssh or telnet client you are using. Make sure that the number of lines is not bigger than your screen! 24 lines is always safe; sometimes you can use 30 or even 50 if you have a big monitor (or are using small Courier fonts). Most things on Unix are designed for windows of 24 lines and 80 characters - using windows smaller than this may result in ugly output. You can verify the number of lines that Unix thinks your window contains using this command: $ stty -a speed 38400 baud; 29 rows; 80 columns ... Make sure the number of rows is exactly equal to the size specified in your ssh or telnet client program. ------------------------------------------ Setting a recognized Terminal type on Unix ------------------------------------------ When starting the vi text editor, you may see errors similar to the following: ex: unknown is not a recognized terminal type. ex: ANSI is not a recognized terminal type. ex: Visual mode requires more cursor capability than the terminal provides. The above errors mean that the terminal type set by ssh or telnet for your login session is not recognized on Unix as valid. Do not attempt to use vi or any other full-screen command if you are getting the above errors. Full-screen commands need to know what kind of terminal you are using, to be able to draw on your screen correctly. Fix your terminal type, first. If you are using a Windows telnet command to connect to Unix, and you get the above errors, you can work around the problem by telling Unix that your terminal type is a vt100. Here's how you can do this at a Bourne shell prompt: $ TERM=vt100 $ export TERM The case of the letters is significant, as is the use of spaces. TERM is upper-case; vt100 is two lower-case letters followed by the number one hundred. There are no blanks at all in the first line. There is at least one blank in the second line. If you always connect to Unix using a vt100-compatible terminal emulator (such as Windows telnet), you can put the above two lines into your login .bash_profile file for automatic execution every time you log in. ----------------------------------------------------- Setting the Unix terminal erase (backspace) character ----------------------------------------------------- This section talks about the backspace key that is located above the main Return/Enter key on your keyboard. It is the key you use to correct your typing mistakes. The Back-Arrow or Left-Arrow key is *not* the same key. The arrow keys and the backspace key send different character sequences and they usually don't do the same things. The backspace key is not necessarily the same as the DEL key. The DEL key may also send a different character sequence than the backspace key. You may find that your backspace key doesn't always work once you are logged in to a Unix system. You may see this when you push backspace (try the command below and see what you get): $ read var test^H^H^H^H $ read var test^?^?^?^? If, instead of erasing the word, you see one of the above, you need to tell Unix about your backspace key. Unix was designed to handle a wide variety of different terminals that used different backspace key conventions; so, sometimes Unix isn't configured to match your particular keyboard. To configure the Unix terminal driver to handle your backspace ("erase") character, use the appropriate stty command. Pick one of the following, depending on what you saw on your screen when you pushed the Backspace key: $ stty erase '^?' or $ stty erase '^H' The '^?' argument is in single quotes to protect the characters from the shell. There are two separate characters in the quoted string. You can put this command into your login .bash_profile file to execute every time you log in. ------------------------------------ Using the telnet client from Windows ------------------------------------ This is for Windows telnet users. After you start telnet and before you type in your login userid and password to the remote Unix system, make sure your telnet session is configured correctly. Here are the things you must verify in telnet on your Windows machine: Menu: Terminal | Preferences Local Echo: Off Blinking Cursor: your choice Block Cursor: your choice VT100 Arrows: On Emulation: VT100/ANSI Buffer Size: 24 Fonts: your choice of Courier-style font Background Color: your choice Anything marked "your choice" does not have to be changed. You only need to set these options once and they will be remembered for this computer. (If you change computers, you will have to reset the options!) Menu: Connect | Remote System ... If you use the telnet Connect|RemoteSystem dialog box, make sure you use the following settings: Host Name: your choice Port: telnet TermType: vt100 Note that the terminal type vt100 is spelled with two lower-case letters followed by the number one hundred. There are no blanks in or around any of these three fields. All the letters are lower-case. Use the full Internet address of your intended host name.