Changes

Linux Remote Shell Notes

3,039 bytes added, 21:29, 24 July 2020
/* auto login ssh */
The following lines were added (+) and removed (-):
== use SSH to execute a remote command ==[[Secure Shell]] (SSH) and Telnet are the two most common remote management protocols.  The configuration of Telnet is a common practice, but it is advisable to use SSH. The reason for this is that Telnet data is sent in plain text in contrast to SSH, which encrypts the data.  Tools like wireshark and snort can be used to intercept unencrypted data over a LAN or extra network connection. You'll need to be able to ssh with automated password or enter the password each time you run the command.Execute a remote command on a host over SSH:telnet - You can install the old telnet server on your linux system and use it to connect sending your password as plain text and then work in a remote shell with everything being sent as plain text, in the event you wish to share everything you are doing with anyone listening with a packet sniffer at any point between you and the remote host. ssh nicolep@192.168.100.10 'reboot'The example above will reboot the remote computer.Multiple commandsssh - SSH works by connecting a client program to an ssh server. Use ssh as the modern secure alternative to telnet. Connect to your linux host from another linux host or a host with a different operating system such as Microsoft Windows. On Microsoft Windows you can use the free ssh client Putty to connect via ssh.  ssh nicolep@192.168.100.10 'uptime; df -h'Show the kernel version, number of CPUs and the total RAM:[[Netcat]] - netcat has been around a long time and should be harmless to have on your system unless you really open things up like a fool. ssh root@192.168.100.10 << EOF uname -a lscpu  | grep "^CPU(s)" grep -i memtotal /proc/meminfo EOFHere is how Nicole can execute her script on the remote computer{{:CentOS_Linux_Distribution_Enable_Telnet}} ssh nicolep@192.168.100.10 'bash -s' < nicolejob.shNicole's script is local on her machine, and she executed it on the remote host.== auto login ssh ==== telnet ==There are still safe and legitimate uses for this over four decade old connection protocol.The OpenSSH ssh utility doesn't accept a password on the command line or on its standard input.  The nanny mentality whereby the developer protects us from ourselves by preventing us from doing something that compromises security, even though the result may be worse.We've already mentioned the lack of security.  Quote, "''The telnet daemons (the process that sits on the server and processes your login) have had numerous vunerabilities and will continue to have them. Running telnetd is just one more old daemon waiting to be used to crack your machine!''" from the post [https://www.linuxquestions.org/questions/linux-networking-3/why-you-should-use-ssh-instead-of-telnet-388664/ Why you should use ssh instead of telnet].OPTIONS FOR SSH AUTOMATEDThere are times when telnet may be useful. On a private LAN (no route to the Internet) or a connection between two machines only (ultra private LAN) the use of telnet is acceptable, quick, and convenient. # Use an SSH key for authentication, instead of a password.# Use sshpass, expect, or a similar tool to automate responding to the password prompt.# Use the SSH_ASKPASS feature to get ssh to get the password by running another program.# Use the insecure host-based authentication, sometimes common on private networks.# Use a custom or modified ssh client adapted from source code, or one that allows for stored password.=== sshpass ===Furthermore, exploration on exactly how ssh is more secure, and where it is not can find validation in the use of telnet.  One of the key advantages of SSH over telnet is that the server authenticates itself to the client before it collects credentials from the client. Most sniffing occurs within the network itself and not outside of the router.  Common ssh installations ignore precautions that protect against external threats, making those networks no more secure when using ssh versus telnet. Install the sshpass utility so that you can automate ssh login including password.  apt install sshpassNow you can automate the login process  sshpass -p "mysecretpass" ssh -o StrictHostKeyChecking=no nicolep@192.168.100.10Custom port example:  sshpass -p "mysecretpass" ssh -o StrictHostKeyChecking=no nicolep@192.168.100.10:9600=== public key authentication ===If there is no threat within the network itself, all traffic tunnelled to a remote network within a secure VPN, and concluding there is no internal threat within that remote network, telnet would offer no lessor security as compared to ssh in the described scenario.In the source host run this only once:   ssh-keygen -t rsa == ssh - The [[Secure Shell]] ==now press ENTER to every fieldThe developer folks hated the "service" command so now we use the new systemctl (System Control) method to start the ssh server daemon.  ssh-copy-id nicolep@192.168.100.10 sudo systemctl start ssh While Telnet was once widely used by administrators for remote management, it does not offer the security mechanisms like SSH, which establishes a secure connection from the host to the remote host.   === [[Secure Shell]] Support for Remote Login ===If the ssh server is not already installed, we will use [[apt-get]] to install. As root or using sudo do the following:  apt-get install openssh-server openssh-client   service ssh start Note: Added 10/17/2016 old cyphers no longer configured, may cause connection problems with legacy ssh clients such as SecureCRT.  ref: https://blog.hqcodeshop.fi/archives/245-SSH-connection-fails.html == Use telnet on Debian / Ubuntu / Mint ==You don't give a rats rear about security and you wish to use good old fashioned telnet (For Debian/Ubuntu/Mint). Ok...Install the Telnet server sudo apt install xinetd telnetdAssign port sudo vi /etc/servicesLook for the line or add a line like telnet        23/tcpRestart xinetd == use SSH to execute a remote command =={{:Secure Shell - use SSH to execute a remote command}} == auto login ssh =={{:Secure Shell - auto login ssh}}== Remote File Copy via SSH ==SCP - Secure Copy Protocol* see: [[Remote_File_Copy_from_the_Linux_Command_Prompt#SCP_-_Secure_Copy_Protocol|Remote File Copy from the Linux Command Prompt with SCP]]== login and non-login shell ==The .bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.When you login (type username and password) via console, either sitting at the machine, or remotely via ssh: .bash_profile is executed prior to the initial command prompt.When you are logged into your machine already and open xterm in your desktop environment then .bashrc is executed prior to seeing a prompt.  The .bashrc is also run when you start a new bash instance by typing /bin/bash in a terminal.== Related Pages ==* [[Remote File Copy from the Linux Command Prompt]][[Category:Computer_Technology]][[Category:Linux]]
Bureaucrat, administrator
16,192
edits