Configure remote Linux server SSH key authentication automatic login under Mac OS x

Source: Internet
Author: User
Tags server port ssh account ssh server


1. Create a public key on the local machine


Open the Universal terminal, execute the following command, ignoring all the output, all the way to enter the cheerful.


Ssh-keygen-t rsa-c  ' Your [email protected] '


-t specifies the key type, which is RSA by default and can be omitted
-C Set comment text, such as your mailbox


2. Copy the public key to the SSH server


The public key ~/id_rsa.pub file generated in the previous step is copied to the ~/.ssh/authorized_keys file under the corresponding user of the SSH server, there are many ways to describe only the three commonly used.


    • [For OSX system] use the SSH-COPY-ID-FOR-OSX tool to copy the public key to the SSH server
brew install ssh-copy-id
ssh-copy-id [email protected] #Replace username and hostname with your ssh server username and IP
    • Use this method when the SSH server username The user directory is not already in the. SSH directory
Cat ~/.ssh/id_rsa.pub | SSH [email protected] "mkdir ~/.ssh; Cat >> ~/.ssh/authorized_keys "
    • Common Way
scp ~ / .ssh / id_rsa.pub [email protected]: ~ / #Copy the public key file to the ssh server
ssh [email protected] #Log in to the ssh server with username and password
mkdir .ssh #If the .ssh directory already exists, you can omit this step
cat id_rsa.pub >> .ssh / authorized_keys #Append the contents of the public key file id_rsa.pub file to the authorized_keys file
3. Quick Login


Once you have completed the above steps, you can log in to the SSH server using the following command, and mom will never have to worry that you can't remember the password.


SSH [email protected] #Replace username with your ssh server username, hostname replaced with the IP of the server


However, every time you still need to enter SSH [email protected], still not the best solution, if you can implement one-click Login or a command to log in is the best, look at the following to see the solution


    • SSH itself also provides a quick way to solve this problem by adding your SSH server information to the ~/.ssh/config configuration file.
Vim ~ / .ssh / config #Without this file, can be created directly


Add file content format as follows:


Host alias #Custom alias
     HostName hostname #Replace with your ssh server ip or domain
     Port port #ssh server port, default is 22
     User user #ssh server username
     IdentityFile ~ / .ssh / id_rsa #The private key file corresponding to the public key file generated in the first step


After you save the file, you can log in to the SSH server using an alias


Alias for SSH alias #alias是你在 ~/.ssh/config file configuration


If you have more than one SSH account to configure, just write it in ~/.ssh/config empty line, as follows:


Host        foo
    HostName        192.168.2.222
    Port            22
    User            test
    IdentityFile    ~/.ssh/id_rsa

Host        alias
    HostName    hostname
    Port        port
    User        user
    • If your local terminal is using ZSH, it's too simple, just add an alias to Zsh
echo "alias ssh-to-username =‘ ssh [email protected] ‘" >> ~ / .zshrc #Replace username and hostname with your server information
source ~ / .zshrc #Reload the changed zshrc file
ssh-to-username #Using alias, one command can log in to your ssh server 
    • If your local terminal is using ITERM2 also can add the profile implementation of one-click login, the specific steps here skip


You may also like the following articles about SSH, please refer to below:



The whole process of configuring SSH service under Ubuntu and problem solving http://www.linuxidc.com/Linux/2011-09/42775.htm



How to install Samba and SSH server http://www.linuxidc.com/Linux/2015-01/111971.htm under Ubuntu 14.04



SSH Service remote access Linux server login Slow http://www.linuxidc.com/Linux/2011-08/39742.htm



The way to improve the speed of SSH login authentication in Ubuntu http://www.linuxidc.com/Linux/2014-09/106810.htm



Enable the SSH service to allow Android phones to access Ubuntu 14.04 http://www.linuxidc.com/Linux/2014-09/106809.htm remotely



How to add two-factor authentication to SSH in a Linux system http://www.linuxidc.com/Linux/2014-08/105998.htm



Configuring the SFTP Environment for non-SSH users in Linux http://www.linuxidc.com/Linux/2014-08/105865.htm



Configuration and management of SSH services on Linux http://www.linuxidc.com/Linux/2014-06/103627.htm



Configure remote Linux server SSH key authentication automatic login under Mac OS x


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.