SSH Tricks Slide 1 SSH Tricks Matthew G. Marsh
SSH Tricks Slide 2 Overview SSH –What is it –How does it work Discussion of Network Topology –Tricks for multiple hosts –Keys and config files –MultiHop tricks Q&A
SSH Tricks Slide 3 SSH What is it –Secure Shell was developed to solve the two most acute problems in the Internet, secure remote terminal logins and secure file transfers. –Essentially an encrypted Remote Utilities replacement How does it work –Set up and generation of an encrypted TCP connection –Authentication can be Password or PubPriv key Yes there are others but that is where the cracks are… –Arbitrary TCP ports - WKP = 22 In this session we will concentrate on SSH1 using key based authentication
SSH Tricks Slide 4 Simple Examples Two hosts –1 has a sshd running on WKP –2 has a client ssh 1 password: # This allows root to login remotely using a password - BAD! Better is to define: ‘PermitRootLogin no’ in the sshd_config file
SSH Tricks Slide 5 Simple Examples Two hosts - preshared key –1 has a sshd running on WKP –2 has a client ssh 1 The way to set this up is as follows: ssh-keygen -t rsa1 -f /home/tech/.ssh/key4mac1 -N “” scp.ssh/key4mac1.pub password: cat >.ssh/config Host 1 User tech Protocol 1 IdentityFile /home/tech/.ssh/key4mac1 Hostname ^D
SSH Tricks Slide 6 A wee bit less Simple Examples Two hosts - preshared key –1 has a sshd running on port 17 –2 has a client ssh 1 The way to set this up is as follows: ssh-keygen -t rsa1 -f /home/tech/.ssh/key4mac1 -N “” scp -P17.ssh/key4mac1.pub password: cat >.ssh/config Host 1 User tech Port 17 Protocol 1 IdentityFile /home/tech/.ssh/key4mac1 Hostname ^D
SSH Tricks Slide 7 A wee bit less Simple Examples Three hosts - Assume: preshared keys –1 has sshd running on port 17 –2 has sshd running on port 27 ssh 2 ‘ssh 1’ The way to set this up is as follows: cat >.ssh/config Host 2 User tech Port 27 Protocol 1 IdentityFile /home/tech/.ssh/key4mac2 Hostname ^D Note you may need ssh -t 2 ‘ssh -t 1’...
SSH Tricks Slide 8 AN4SCD Buy a copy of “SSH” by Daniel J. Barrett & Richard E. Silverman pub. O’Reilly (ISBN: ) Read it I use openssl 0.9.7c with openssh 2.9.9p2-PS I do not use any other version of SSH I use Protocol 1 on purpose I use TCP Wrappers w/ IPv6 extensions I keep tight controls using TCP Wrappers
SSH Tricks Slide 9 AN4SCD - 2 Static Compile methods Get the latest openssl 1. Compile it static with the /usr/static directory target./config --openssldir=/usr/static --prefix=/usr/static no-shared 2. Get openssh-2.9.9p2-PS prefix=/usr/static --with-ssl-dir=/usr/static --with-ipaddr- display --with-ipv4-default –with-tcp-wrappers compile it and install Edit the sshd config file Make sure you also change the paths for the keys!!
SSH Tricks Slide 10 AN4SCD – sshd_config Port 17 Protocol 1 ListenAddress HostKey /usr/static//etc/ssh_host_key KeyRegenerationInterval 3600 ServerKeyBits 768 SyslogFacility AUTH LogLevel INFO LoginGraceTime 600 PermitRootLogin no StrictModes yes RSAAuthentication yes PubkeyAuthentication yes RhostsAuthentication no IgnoreRhosts yes RhostsRSAAuthentication no PasswordAuthentication yes PermitEmptyPasswords no ChallengeResponseAuthentication no X11Forwarding no X11DisplayOffset 10 PrintMotd yes KeepAlive yes
SSH Tricks Slide 11 Fun Examples - 1 Using commands attached to keys –On the server define a command in the authorized_keys file associated with a key –Format is “command=“my/command/string”…key data… EX: command=“/bin/ls -al /logs”ABCDEF Then ssh with the appropriate key will only allow you to execute this command. Note that this is per key so…
SSH Tricks Slide 12 Fun Examples – 1A Each connection performs a different function: command=“/bin/tar –C /var –zc logs/” command=“/bin/tar –C / –zc etc/” command=“/bin/tar –C /home –zc mgm/mail/” First one is keytar1 Second one is keytar2 Third one is keytar3
SSH Tricks Slide 13 Fun Examples – 1B Assuming we have setup the config file then: ssh 1 | tar –zxv Will generate a copy including timestamps and permissions of the logs/ directory ssh 2 | tar –zxv Will generate a backup copy of our remote etc/ directory (assuming we have permission…)
SSH Tricks Slide 14 Fun Examples - 2 MultiBounce Sessions –Using the three hosts example from earlier Consider: ssh 1 ‘ssh 2 /bin/tar -C /home -zc myhomedir/’ | tar -zxv ssh 1 ‘ssh 2 “ssh 3 /bin/tar -C /home -zc myhomedir/”’ | tar -zxv Note that there are limits…
SSH Tricks Slide 15 Q & A
SSH Tricks Slide 16 This is The