Changes

Linux Remote Shell Notes

873 bytes added, 21:29, 24 July 2020
/* auto login ssh */
The following lines were added (+) and removed (-):
[[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.  [[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.{{:CentOS_Linux_Distribution_Enable_Telnet}}== telnet ==There are still safe and legitimate uses for this over four decade old connection protocol.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].There 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.  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.  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.== ssh - The [[Secure Shell]] ==[[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.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== Install and use telnet ==== Use telnet on Debian / Ubuntu / Mint =={{:CentOS_Linux_Distribution_Enable_Telnet}}You'll need to be able to ssh with automated password or enter the password each time you run the command.{{:Secure Shell - use SSH to execute a remote command}} Execute a remote command on a host over SSH: ssh nicolep@192.168.100.10 'reboot'The example above will reboot the remote computer. Multiple commands ssh nicolep@192.168.100.10 'uptime; df -h' Show the kernel version, number of CPUs and the total RAM: ssh root@192.168.100.10 << EOF uname -a lscpu  | grep "^CPU(s)" grep -i memtotal /proc/meminfo EOF Here is how Nicole can execute her script on the remote computer 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. {{:Secure Shell - auto login ssh}}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. OPTIONS FOR SSH AUTOMATED# 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 ===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 ===In the source host run this only once: ssh-keygen -t rsa Now you've generated the public key.  It needs to be copied onto the remote host.  ssh-copy-id -i ~/.ssh/id_rsa.pub nicolep@192.168.100.10add identities to the ssh-agent – the authentication agent on the local host. ssh-addnow press ENTER to every field ssh-copy-id nicolep@192.168.100.10 === expect ===Example script #!/usr/bin/expect set timeout 15 set cmd [lrange $argv 1 end] set password [lindex $argv 0] eval spawn $cmd expect "assword:" send "$password\r"; interact Another example #!/usr/bin/expect -f #  ./ssh.exp password 192.168.100.10 id set pass [lrange $argv 0 0] set server [lrange $argv 1 1] set name [lrange $argv 2 2] spawn ssh $name@$server match_max 100000 expect "*?assword:*" send -- "$pass\r" send -- "\r" interact And finally, a more elaborate example can be found here:* http://www.techpaste.com/2016/02/ssh-login-with-password/== 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