Outputs what IT inexperienced school students have learned: neutral_face: This is my first post. Thank you.
A protocol that securely communicates with a remote computer using encryption and authentication technology when you want to work in a remote server (remote server).
・ You can operate safely while avoiding the risk of eavesdropping on communications. -File operations and configuration file editing can be performed on the server.
You can log in using two methods: password authentication and public key authentication.
In order to use SSH, it is necessary to install software called SSH server remotely and SSH client locally. However, it is installed by default on Linux servers and Mac OS, so there is no need to install it.
$ ssh [Login user name]@[IP address]
When you log in for the first time, you will be asked if you really want to connect, so enter yes Next you will be asked to enter the password, so you can log in by entering the password
macmini: ~ user1 $ ssh [email protected]
The authenticity of host '192.168.2.67(192.168.2.67)' can't be established.
RSA key fingerprint is c3 : e3 : 8d :5e ea :58 : 0e :a9 : e5 : 03 : 34 : 56 : b3 : ca : a3 : 60.
Are you sure you want to continue connecting (yes, no)?yes ← enter yes
Warning : Permanently added '192.168.2.67'(RSA) to the list of known hosts.
[email protected]'s passward:← Enter password
Last login: Sat Aug 23 18:34:30 2014 from 192.168.2.67
[hinako@localhost ~]$
It is not good for security that an unspecified number of people can enter the server Restrict who can create two files, *** private key *** and *** public key ***, on the server The public key will be sent with you when you start SSHing to the server. Store the private key in your local environment. The public key generates the cipher, and in the local environment, the cipher sent from the server is decrypted with the private key. In this way, the exchange of information between the server and the local environment is secure.
procedure
~ $ cd .ssh # .Move to ssh directory
.ssh $ ssh-keygen -t rsa #Create public and private keys
After entering, the following will be displayed, and enter the private key storage location and the password to be set for the private key.
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/hogehoge/.ssh/id_rsa): [Where to put the private key]
Enter passphrase (empty for no passphrase): [password]
Enter same passphrase again: [password]
The public key is stored in *** ~ / .ssh / id_rsa.pub *** and the private key is stored in *** ~ / .ssh / id_rsa *** Enter the following command, and if the output result contains the following two, the creation is successful.
$ ls
=> [Key name]_key_rsa [Key name]_key_rsa.pub
Use the cat command to check the contents of the public key to see if the public and private keys have been created.
#Check the contents of the public key
$ cat [Public key]_key_rsa.pub
#Check the contents of the private key
$ cat [Private key]_key_rsa
When I run the command, a complex string is displayed on the terminal. This is the contents of the public and private keys you created earlier.
-Copy the public key file of the local environment to the remote server
Use the scp command to copy the public key remotely to the server *** scp command *** A command that allows you to specify the destination directory and send a file
$ scp ~/.ssh/id_rsa.pub [username]@ [IP address]:~/.ssh
$ ssh -i [The name of the downloaded key].pem ec2-user@[Elastic IP associated with the created EC2 instance]
-Add the contents of the public key file of the local environment to the public key file of the remote server.
Until now, in the local environment, the public key was saved in id_rsa.pub, but in the remote server, the public key is saved in ~ / .ssh / authorized_keys.
#Log in to the remote server
$ ssh [username]@ [IP address]
# .Move to ssh directory
$ cd ~/.ssh
#Remote server public key file (~/.ssh/authorized_create keys)
touch .ssh/authorized_keys
#Add the contents of the public key
$ cat ~/id_rsa.pub >> authorized_keys
Finally, set permissions for the .ssh directory and the authorized_keys file. Set all read / write / execute permissions in the .ssh directory and read / write permissions in the authorized_keys file.
# .ssh directory and authorized_Set permissions for keys file
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys
#Log in to the remote server
$ ssh [username]@ [IP address]
After typing the command, the following display will be displayed. (1) Enter the password described in the #Enter password to set the public key and private key to the generated # private key. After that, if [User name] @ [IP address]% is displayed, login is successful: v:
Enter passphrase for key '~/.ssh/id_rsa':← Enter password
[username]@ [IP address]%← Successful login to SSH server
Recommended Posts