summaryrefslogtreecommitdiff
path: root/.cheat/cheat/ssh
blob: e4087a948c0594c1912e7486471a3a6d9e3e99f6 (plain)
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
# To ssh via pem file (which normally needs 0600 permissions):
ssh -i /path/to/file.pem user@example.com

# To connect on an non-standard port:
ssh -p 2222 user@example.com

# To connect and forward the authentication agent
ssh -A user@example.com

# To execute a command on a remote server:
ssh -t user@example.com 'the-remote-command'

# To tunnel an x session over SSH:
ssh -X user@example.com

# Redirect traffic with a tunnel between local host (port 8080) and a remote
# host (remote.example.com:5000) through a proxy (personal.server.com):
ssh -f -L 8080:remote.example.com:5000 user@personal.server.com -N

# To launch a specific x application over SSH:
ssh -X -t user@example.com 'chromium-browser'

# To create a SOCKS proxy on localhost and port 9999
ssh -D 9999 user@example.com

# -X use an xsession, -C compress data, "-c blowfish" use the encryption blowfish
ssh user@example.com -C -c blowfish -X

# For more information, see:
# http://unix.stackexchange.com/q/12755/44856

# Copy files and folders through ssh from remote host to pwd with tar.gz compression
# when there is no rsync command available
ssh user@example.com "cd /var/www/Shared/; tar zcf - asset1 asset2" | tar zxf -

# Set up SSH Passwordless login using ssh keygen
# 
# 1. On client, generate public/private keys
 
ssh-keygen -t rsa
 
# 2. Login to server and make sure that a .ssh directory exists in user's home directory. Create it otherwise.
#
# 3. Use ssh from client to upload the public key to the server, and place it in the users's .ssh directory and call it authorized_keys

[user@client]$ cat .ssh/id_rsa.pub | ssh user@server 'cat >> .ssh/authorized_keys'

# 4. Set Permissions on server

[user@client]$ ssh user@server 'chmod 700 .ssh; chmod 640 .ssh/authorized_keys'

# 5. Can now login to server with the use of password.