SSH: Difference between revisions
No edit summary |
(→SCP) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== SSH == | == 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 17: | Line 20: | ||
'''Example:''' | '''Example:''' | ||
<code> | <code>scp examplefile yourusername@yourserver:/home/yourusername/</code> | ||
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. | |||
To download a file from a remote server to your local computer: | |||
<code>scp sshusername@10.10.10.123:/remote/file.txt /home/user/Downloads/</code> | |||
== 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 == | |||
<ol> | |||
<li>[http://man.he.net/?topic=ssh§ion=all ssh man page]</li> | |||
</ol> |
Latest revision as of 23:53, 2 November 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.
To download a file from a remote server to your local computer:
scp sshusername@10.10.10.123:/remote/file.txt /home/user/Downloads/
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.)