-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbasic_shell_logging.Rmd
125 lines (102 loc) · 3.37 KB
/
basic_shell_logging.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
---
title: "SSH onto a HPC"
subtitle: ""
author: "Alexis Lucattini"
date: "2017/08/17"
output:
xaringan::moon_reader:
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
# Installing commandline tools (Mac OSX)
### (0 to 10 minutes)
Mac OSX by default does not have command line tools installed.
This is a simple fix as shown [here](http://railsapps.github.io/xcode-command-line-tools.html)
Open up 'Terminal' and type in the following.
```{bash, eval=FALSE}
xcode-select -p
```
`/Applications/Apple Dev Tools/Xcode.app/Contents/Developer` shoud appear as the output.
If not, type:
```{bash, eval=FALSE}
xcode-select --install
```
You will also need homebrew. Type the following line into terminal.
```{bash, eval=FALSE}
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
```
---
# Installing commandline tools (Windows)
### (0 to 10 minutes)
Install [Git Bash](https://gitforwindows.org/).
Open up the Git Bash app.
```{bash, eval=FALSE}
# Ensure ssh and ssh-copy-id commands exist
which ssh
which ssh-copy-id
# These two commands should return these two outputs respectively.
/usr/bin/ssh/
/usr/bin/ssh-copy-id
```
---
# SSH into the cluster.
Let's first try and ssh into the cluster. SSH stands for *secure shell login*
```{bash, eval=FALSE}
# Use your login credentials to ssh onto the server
ssh <username>@<server_name>
# This should prompt you for your password
```
The following commands will be needed to navigate around:
`pwd, ls, cd`
The following commands will be needed to move and transfer files:
`mv, cp, rm, touch`
You can practise these on your own computer first before trying on the server.
Type `exit` to leave the server and return to your computer.
---
# Passwords are annoying.
Let's use a key so that we don't have to continue entering our password when logging in.
```{bash, eval=FALSE}
# Install ssh-copy-id
brew install ssh-copy-id
# Create an ssh-key
ssh-keygen -t rsa # Then press enter twice.
# Now copy ssh key to server, you will be prompted for your password, one last time
ssh-copy-id -i ~/.ssh/id_rsa <username>@<server_name>
# Now try log in.
ssh username@<server_name>
```
---
# Troubleshooting
## I have copied across my id, but it still won't log in automatically.
Try change the permissions on your .ssh folder
```{bash, eval=FALSE}
chmod -R 700 ~/.ssh
```
If this still doesn't work, make sure that only you have permissions on your home directory.
View this [Stack-Exchange Thread](https://unix.stackexchange.com/questions/37164/ssh-and-home-directory-permissions) for more details.
---
# Troubleshooting
## I can't install brew or ssh-copy-id (Mac OSX)
That's okay, we can copy our id onto the server
```{bash, eval=FALSE}
scp ~/.ssh/id_rsa.pub <username>@<server>:
ssh <username>@<server_name>
# Now we're on the server; Create a .ssh directory for the server
mkdir -p -m 700 ~/.ssh
# Now append that id_rsa.pub key to our list of authorized keys
cat id_rsa.pub >> ~/.ssh/authorized_keys
# Our work here is done. Let's delete the .pub file and leave the server
rm id_rsa.pub
exit
```
---
# Further reading.
### Steve Parker: Shell scripting
Very comprehensive guide to using the 'Terminal'.
Starts at the very basics.
https://www.amazon.com.au/Shell-Scripting-Tutorial-Steve-Parker-ebook/dp/B00C2EGNSA
Free version is here:
https://www.shellscript.sh