https://habrahabr.ru/flows/admin/
https://www.reddit.com/r/Python/comments/4pkl2a/python_and_ssh/
https://en.wikibooks.org/wiki/OpenSSH/Cookbook/Proxies_and_Jump_Hosts
http://vitus-wagner.livejournal.com/1256013.html
FTP
"prompt off" before issuing the mget
!ls to see the local folder
SSH
ssh cacher@cache-server "bash -s" < script.sh
for s in "${servers[@]}"; { ssh cacher@$s "bash -s" < script.sh }
ssh -t user@servername "$(< ./my-setup-script.sh)"
ssh -t user@servername /bin/bash < my-setup-script.sh
https://semaphoreci.com/community/tutorials/getting-started-with-ssh
https://github.com/jpalardy/warp
http://blog.urfix.com/25-ssh-commands-tricks/
http://serversforhackers.com/editions/2014/07/01/ssh-tricks/
https://news.ycombinator.com/item?id=7658459
http://blog.tjll.net/ssh-kung-fu/
http://stackoverflow.com/questions/285015/linux-prevent-a-background-process-from-being-stopped-after-closing-ssh-client
http://www.pyrosoft.co.uk/blog/2012/01/24/how-to-bulk-add-an-ssh-key-to-multiple-servers/
http://shebang.brandonmintern.com/tips-for-remote-unix-work-ssh-screen-and-vnc
http://techportal.inviqa.com/2013/09/24/ssh-tips-and-tricks/
http://habrahabr.ru/company/centosadmin/blog/212833/
Paramiko - python ssh client
https://learnxinyminutes.com/docs/shutit/
https://habrahabr.ru/post/283364/
https://github.com/knipknap/exscript
https://pypi.python.org/pypi/paramiko ssh from python
http://www.iodigitalsec.com/ssh-sftp-paramiko-python/
http://habrahabr.ru/post/150047/
https://amoffat.github.io/sh/tutorials/2-interacting_with_processes.html
https://news.ycombinator.com/item?id=7321104
http://habrahabr.ru/post/122445/
http://blogs.perl.org/users/smylers/2011/08/ssh-productivity-tips.html
http://blog.ksplice.com/2010/08/six-things-i-wish-mom-told-me-about-ssh/
http://matt.might.net/articles/ssh-hacks/
http://www.jedi.be/blog/2010/08/27/ssh-tricks-the-usual-and-beyond/
http://tychoish.com/rhizome/9-awesome-ssh-tricks/
http://mortalpowers.com/news/master-the-art-of-ssh-tunneling-and-forwarding
http://aross.se/2015/07/27/how-to-ssh-through-ssh-proxy.html
http://www.ylsoftware.com/news/270
http://community.livejournal.com/ru_linux/2625024.html
how to generate very secure SSH key valid for one year (52 weeks) with "13.04" comment for its public part:
ssh-keygen -t rsa -b 4096 -V +52w -C 13.04
rsa -in private_key_with_pass_phrase -out private_key_without_pass_phrase
~/.ssh/config
To avoid typing long hostnames in ssh/ftp/scp в ~/.ssh/config вносим:
Host pup
HostName super.puper.shell.net.org
User hoster2956
Protocol 1
Now we can use pup instead long host name:
scp ~/.screenrc pup:~
.ssh/config
File format: as many of the following blocks as you like
it becomes hard to remember all that host specific information: username, ip address, identity file, non-standard port or local/remote port forwarding
.ssh_config to rescue. Here is a sample to give you an idea (file~/.ssh/config):
Compression yes IdentityFile ~/.ssh/id_rsa LogLevel ERROR Port 22 Host h1 HostName 192.168.91.57 User master IdentityFile ~/.ssh/h1.pem Host db1 HostName usca45d1.example.com User pg LocalForward 5432 127.0.0.1:5432
The above configuration let me access those hosts simply by name, e.g.:
ssh h1 scp schema.sql db1:~/
SSH tunelling
http://www.linuxjournal.com/content/ssh-tunneling-poor-techies-vpn
https://ecksit.wordpress.com/2007/05/19/port-tunneling-howto/
http://mortalpowers.com/news/master-the-art-of-ssh-tunneling-and-forwarding
ssh -L удаленный_порт:localhost:5432 me@top-me.org -N
Passwodless SSH ans SCP
http://opensourcehacker.com/2012/10/24/ssh-key-and-passwordless-login-basics-for-developers/
http://www.thegeekstuff.com/2008/06/perform-ssh-and-scp-without-entering-password-on-openssh/
http://habrahabr.ru/blogs/linux/39116/
cat /home/user1/.ssh/id_rsa.pub | ssh root@remote_server ‘cat >> /home/user2/.ssh/authorized_keys’
cat ~/.ssh/id_rsa.pub | ssh user@remote_server "cat >> .ssh/authorized_keys"
http://shebang.brandonmintern.com/tips-for-remote-unix-work-ssh-screen-and-vnc
http://nerderati.com/2011/03/simplify-your-life-with-an-ssh-config-file/
SSH hacks
http://matt.might.net/articles/ssh-hacks/
Copying to remote host via pipes using ssh$ echo "Hello world" | ssh anotherhost.com 'cat > /tmp/1'
$ ssh anotherhost.com 'cat /tmp/1'
Check files on remote machine
http://xmodulo.com/2013/05/how-to-check-if-file-exists-on-remote-server.html
Remote script execution
http://shiroyasha.github.io/running-script-on-remote-machines.html
http://www.bogotobogo.com/python/python_ssh_remote_run.php
http://shiroyasha.github.io/comparing-files.html
http://www.reddit.com/r/Python/comments/zr3ld/help_i_want_to_run_a_python_script_a_specific/
http://stackoverflow.com/questions/305035/how-to-use-ssh-to-run-shell-script-on-a-remote-machine
CMD="source /usr/sap/ANA/home/.profile; COMMAND_WHICH_DEPENDS_FROM_PROFILE"
for i in $(seq 76 80); do
ssh user@server$i $CMD &
done
wait
----------- remote shutdown example --------------
#!/bin/bash
# Iterate through each remote host in the file /root/tools/machines
while read rhost; do
ssh root@$rhost "/sbin/shutdown -h now"
done < /root/tools/machines
-------------------------------------
If Machine A is a Windows box, you can use plink (part of PuTTY) with the -m parameter,
and it will execute the local script on the remote server.
plink root@MachineB -m local_script.sh
If Machine A is a Unix-based system, you can use:
ssh root@MachineB 'bash -s' < local_script.sh
You shouldn't have to copy the script to the remote server to run it.
Don't forget to escape variables if you want to pick them up from the destination host.
user@host> ssh user2@host2 "echo \$HOME"
prints out /home/user2
However
user@host> ssh user2@host2 "echo $HOME"
prints out /home/user
http://www.ibm.com/developerworks/aix/library/au-satdistadmin/index.html
http://ru-linux.livejournal.com/2819689.html?style=mine&nc=24#comments
http://backreference.org/2011/08/10/running-local-script-remotely-with-arguments/
http://stackoverflow.com/questions/305035/how-to-use-ssh-to-run-shell-script-on-a-remote-machine
Python frameworks for remote execution:
http://salt.readthedocs.org/en/latest/topics/index.html
Telnet /ssh automation: Expect
http://habrahabr.ru/blogs/sysadm/131835/
https://pexpect.readthedocs.io/en/stable/
(echo password; echo "ls -l"; sleep 1; echo "quit" ) | telnet machine_name
http://www.osnews.com/story/10929
https://github.com/j3parker/hijack
https://likegeeks.com/expect-command/
http://empty.sourceforge.net/
http://linsovet.com/telnet-automatization-without-expect
http://stackoverflow.com/questions/1491494/telnet-automation-scripting
http://linuxgazette.net/50/tag/34.html
https://pexpect.readthedocs.org/en/latest/
pexpect
expect autoexpect
man autoexpect - generates expect script
/usr/bin/expect
reads myfile.sh and execute
$ cat test.exp #!/usr/bin/expect -f spawn ssh root@gw-home expect "root\@gw-home\:\~\# " set infile [open "myfile.sh" r] while { [gets $infile line] >= 0 } { send "$line\n" expect "root\@gw-home\:\~\# " } close $infile
SCP
scp [options] [[user@]host1:]filename1 ... [[user@]host2:]filename2
scp -r dvader@deathstar.com:somedir somedir
When using wildcards (e.g., * and ? ) to copy multiple files from a remote system, be sure to enclose the filenames in quotes. This is because the Unix shell, not the scp command, expands unquoted wildcards.
scp directory recursively
scp -C -p -r user@hostname:/folder destination_folder
-C means compress, -p means to preserve file times, -r means to recursively copy directories.
How to rsync files over ssh running the rsync on the destination host
rsync -avz -e ssh remote_user@remote_host:/remote/dir /local/dir/
in this case you’d have to enter remote_user password. If you are running rsync on a regular basis, create ssh keys with no password and copy public key to the .ssh/authorized_keys file on the remote user you are connecting as on the remote host.
You can also copy multiple files or directories from the destination host:
rsync -avz -e ssh remote_host:/remote_dir/file1 remote_dir2/file2 /local/dir
Meaning of options used (from rsync man page
-a, –archive archive mode; same as -rlptgoD (no -H)
-z, –compress compress file data during the transfer
-v, –verbose increase verbosity
-e, –rsh=COMMAND specify the remote shell to use
tmux
http://pragprog.com/book/bhtmux/tmux
http://perltricks.com/article/an-introduction-to-tmux/
https://github.com/jamesottaway/tmux-up
http://www.drbunsen.org/the-text-triumvirate/
http://www.reddit.com/r/programming/comments/2rbbeb/zsh_tmux_and_vim_the_text_triumvirate/
https://news.ycombinator.com/item?id=7275911
https://github.com/tmuxinator/tmuxinator
http://www.danielmiessler.com/study/tmux/
Host $ALIAS <-- whatever you want here Hostname www.example.com User someuser Port 1234