Scripting with Bash Compact Course @ MPE Moritz August March 14 - 16, 2017 Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 1
Part IV Working Remotely And More Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 2
Working remotely - ssh, scp and tmux ping • ping hostname • Useful to find out whether some machine is down or has no connection. Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 3
Working remotely - ssh, scp and tmux ping • ping hostname • Useful to find out whether some machine is down or has no connection. ssh and scp - security by encryption • Developed 1995 to allow secure connections between computers • ssh username@computername log in onto computername as username • scp -r * username@computername:<path_rel_to_home> • scp *.txt username@computername:/<absolute_path> • scp "username@computername:path/*.*"./ – copy all remote files in folder path to current directory • Quotes necessary for remote wildcards Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 3
Working remotely - ssh, scp and tmux Tunneling connections ssh ssh XX 22 XY 22 gname rname local @gate @remote • You can ssh from local machine to gate • You can (e.g.) ssh from gate to remote • You cannot directly access remote • Then use ssh for tunneling the connection Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 4
Working remotely - ssh, scp and tmux Tunneling connections ssh ssh XX 22 XY 22 gname rname local @gate @remote ssh XX 22 XY 22 gname rname local 8888 @gate @remote • You can ssh from local machine to gate • You can (e.g.) ssh from gate to remote • You cannot directly access remote • Then use ssh for tunneling the connection ssh -L 8888: < remote >:22 <gname >@<gate > # then in other terminal scp -P 8888 file.txt <rname >@localhost:some/dir ssh -p 8888 <rname >@localhost Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 4
Working remotely - tmux • during a typical session, many terminals are used • if working remote, this means opening many ssh connections • for each login/logout, everything has to be closed/opened again • tmux solves all these problems by creating virtual terminals • tmux commands can be accessed by Ctrl+b • Ctrl+b, % creates a new pane • Ctrl+b, " splits pane into two panes • Ctrl+b, x kills pane • Ctrl+b, c creates new window • Ctrl+b, & kill window • Ctrl+b, <Arrow> switch pane • Ctrl+b, <Number> switch window • Ctrl+b, d detach from tmux • tmux a attach to tmux Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 5
Some more commands you should know basename "this/is/the/path/to/a.file" dirname "this/is/the/path/to/a.file" time sleep 3 time for i in ` seq 100000 ` ; do a= $ [3* $ i]; done users groups du -sh df -h ln -s <file > <link > Moritz August: Scripting with Bash Compact Course @ MPE, March 14 - 16, 2017 6
Recommend
More recommend