SSH, PTS and TTY page index
This is the current content sections of the page: SSH, DSH, SCP
SSH

Introduction

Difference between Shell, Console and Terminal:
The terminal connects to the console where the shell is presented.
A TTY is a teletypewriter. It is essentially the equivalent of the console port but is often virtualized in software. If you jump to a different virtual console on your Linux machine using ctrl+alt+f1 to 12 combination and login in, you can see the multiple consoles with logged in users by running the who command. Then there are PTS devices which are Pseudo Terminal Slaves, a virtual device of sorts. They are a form of TTY, but one that is emulated to allow a TTY connection over a network or some other means. SSH and Telnet are good examples of programs that use PTS devices.

SSH: Tunneling

Source: www.howtogeek.com
To use local forwarding, connect to the SSH server normally, but also supply the -L argument.
The syntax is:
ssh -L local_port:remote_address:remote_port username@server.com For example, let’s say the database server at your office is located at 192.168.1.111 on the office network. You have access to the office’s SSH server at ssh.youroffice.com , and your user account on the SSH server is bob . In that case, your command would look like this:
ssh -L 8888:192.168.1.111:1234 bob@ssh.youroffice.com SSH Agent:
eval `ssh-agent -s` & ssh-add Add to your Bash config file:
SSHAGENT=/usr/bin/ssh-agent SSHAGENTARGS="-s" if [ -z "$SSH_AUTH_SOCK" -a -x "$SSHAGENT" ]; then eval `$SSHAGENT $SSHAGENTARGS` trap "kill $SSH_AGENT_PID" 0 fi This will start an agent automatically for each new command prompt window that you open (which is suboptimal if you open multiple command prompts in one session, but at least it should work).

SSH Key Management

Add a passphrase to a key generated without:
ssh-keygen -p -f keyfile Remove a passphrase from a key:
ssh-keygen -p [-P old_passphrase] [-N new_passphrase] [-f keyfile] Leave the new_passphrase blank.
Fun ssh command:
for s in $(cat server-cluster); \ do ssh -i $PRIVATE_KEY USER_NAME@$s "sudo su -c 'cd /root/dockerComposeWebServer && \ docker-compose down && docker-compose up -d'";done


DSH

Server Group: /etc/dsh/group/
options : -f machinefile : Add all machines found in the specified file to the list of machines that the specified command is executed. -g groupname : Add all machines found in /etc/dsh/group/groupname to the list of machines that the specified command is executed. -w : Executes on each machine and waits for the execution finishing before moving on to the next machine. -c : Executes shell concurrently. -M : Prepends machine names on the standard output. Useful to be used in conjunction with the --concurrent-shell option so that the output is slightly more parsable. Examples:
dsh -g POOL_Dir/Server_Group_File "df -h /" dsh -c -m $(grep serverSname* /etc/dsh/group/pool/servers_types|perl -pe 'print "," if($i++);chomp;') \ '/users/dev/script.pl /logs/script.pl_log- 20181202[5-9]* /logs/script.pl_log'


SCP

Syntax

Copy the file "foobar.txt" from a remote host to the local host:
scp your_username@remotehost.edu:foobar.txt /some/local/directory Copy the file "foobar.txt" from the local host to a remote host:
scp foobar.txt your_username@remotehost.edu:/some/remote/directory Copy the directory "foo" from the local host to a remote host's directory "bar":
scp -r foo your_username@remotehost.edu:/some/remote/directory/bar Copy the file "foobar.txt" from remote host "rh1.edu" to remote host "rh2.edu":
scp your_username@rh1.edu:/some/remote/directory/foobar.txt \ your_username@rh2.edu:/some/remote/directory/ Copying the files "foo.txt" and "bar.txt" from the local host to your home directory on the remote host:
scp foo.txt bar.txt your_username@remotehost.edu:~ Copy the file "foobar.txt" from the local host to a remote host using port 2264:
scp -P 2264 foobar.txt your_username@remotehost.edu:/some/remote/directory Copy multiple files from the remote host to your current directory on the local host:
scp your_username@remotehost.edu:/some/remote/directory/\{a,b,c\} . scp your_username@remotehost.edu:~/\{foo.txt,bar.txt\} .

Performance

By default scp uses the Triple-DES cipher to encrypt the data being sent. Using the Blowfish cipher has been shown to increase speed. This can be done by using option -c blowfish in the command line.:
scp -c blowfish some_file your_username@remotehost.edu:~ It is often suggested that the -C option for compression should also be used to increase speed. The effect of compression, however, will only significantly increase speed if your connection is very slow. Otherwise it may just be adding extra burden to the CPU. An example of using blowfish and compression::
scp -c blowfish -C local_file your_username@remotehost.edu:~