SSH: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
== SSH == | |||
SSH allows you to connect to a shell on a remote computer. | |||
'''Example:''' | |||
<code>[user@localhost ~]$ ssh username@yourserver</code> | |||
Use -p to set the port. | |||
'''Example:''' | '''Example:''' | ||
<code>[user@localhost ~]$ ssh -p 123 username@yourserver</code> - connects using port 123. | |||
Line 20: | Line 23: | ||
This example sends '''examplefile''' from the directory you're currently in to '''/home/yourusername/''' on '''yourserver''' | This example sends '''examplefile''' from the directory you're currently in to '''/home/yourusername/''' on '''yourserver''' | ||
Note that scp uses <code> -P </code> to specify the port. | |||
== SSH Keys == | |||
ssh keys are used to connect to an ssh server without a password. | |||
'''Step 1: Create a key-pair on the client machine''' | |||
<code>ssh-keygen -t rsa</code> | |||
After you enter the above command, ssh-keygen will ask you where you want to store the key. You can just press ENTER to accept the default location. | |||
Next, it will ask you to enter a passphrase. You can either enter a passphrase, or press ENTER to not use a passphrase. | |||
(Note that you don't need a pass-phrase, but if you don't use one, anyone that somehow gets a copy of the key can get into your server.) | |||
SSH keygen will spit out a bunch of stuff, and you're done with step 1. | |||
'''Step 2: Copy the public key to the server''' | |||
<code>ssh-copy-id <i>user</i>@<i>server_IP</i></code> | |||
This will copy the public key over to the server. Now try to connect via SSH, and it should connect without a password (unless you entered a pass-phrase. In that case, you need to enter the pass-phrase to connect.) | |||
== References == | == References == |
Revision as of 22:58, 14 January 2017
SSH
SSH allows you to connect to a shell on a remote computer.
Example:
[user@localhost ~]$ ssh username@yourserver
Use -p to set the port.
Example:
[user@localhost ~]$ ssh -p 123 username@yourserver
- connects using port 123.
SCP
You can also use scp to securely transfer files.
Example:
scp examplefile yourusername@yourserver:/home/yourusername/
This example sends examplefile from the directory you're currently in to /home/yourusername/ on yourserver
Note that scp uses -P
to specify the port.
SSH Keys
ssh keys are used to connect to an ssh server without a password.
Step 1: Create a key-pair on the client machine
ssh-keygen -t rsa
After you enter the above command, ssh-keygen will ask you where you want to store the key. You can just press ENTER to accept the default location.
Next, it will ask you to enter a passphrase. You can either enter a passphrase, or press ENTER to not use a passphrase. (Note that you don't need a pass-phrase, but if you don't use one, anyone that somehow gets a copy of the key can get into your server.)
SSH keygen will spit out a bunch of stuff, and you're done with step 1.
Step 2: Copy the public key to the server
ssh-copy-id user@server_IP
This will copy the public key over to the server. Now try to connect via SSH, and it should connect without a password (unless you entered a pass-phrase. In that case, you need to enter the pass-phrase to connect.)