Home > Article > Operation and Maintenance > How to log in to Linux server on Mac using secret key
The following will introduce how to log in to the Linux server on Mac using a secret key. I hope it will be helpful to friends who need it. For more Linux usage tutorials, you can directly visit Linux Video Tutorial to learn!
Introduction
Configure SSH key on Mac to log in to remote Linux
Related configuration
1. Create a local SSH key
Generate a key pair locally
ssh-keygen -t rsa -C 'youxiang@aliyun. com'
-t 指定密钥类型,默认即 rsa -C 设置注释文字,比如你的邮箱
You can set the private key password. The password I set here is 12345
The generated key defaults to the home directory. ssh directory
2. Upload the public key to the remote Linux server
Use scp to copy the public key to the remote server
scp -P
The root user I use here uploads and needs to enter Login password
Configure the private key of remote Linux
3. Log in to the remote Linux server and append the public key to the server ssh authentication file:
cat /home/id_rsa.pub >> ~/.ssh/authorized_keys
If there is no .ssh directory or authorized_keys file in the home directory, you can create it and grant authorized_keys File 600 permissions
Then executecat /home/id_rsa.pub >> ~/.ssh/authorized_keys
4. Local ssh connection
ssh -p
5. If the default port is not modified, you can ignore the port No.
ssh root@114.11.11.111
Create configuration file to quickly log in
You need to enter the user and IP address every time you log in, which is too Trouble, you can add a configuration file and use an alias to log in
vi ~/.ssh/config
Host alias #自定义别名 HostName 114.11.11.110 #替换为你的ssh服务器ip或domain Port 22 #ssh服务器端口,默认为22 User root #ssh服务器用户名 IdentityFile ~/.ssh/id_rsa #第一个步骤生成的公钥文件对应的私钥文件
That’s it Use ssh jd
to log in
Prohibit Linux from using account password to log in
1.cd /etc/ssh/
2. Modify the SSH configuration file vi sshd_config
RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys #AuthorizedKeysCommand none #AuthorizedKeysCommandRunAs nobody #默认PasswordAuthentication 为yes,即允许密码登录,改为no后,禁止密码登录 PasswordAuthentication no
3. Restart the ssh service
systemctl restart sshd.service
The above is the detailed content of How to log in to Linux server on Mac using secret key. For more information, please follow other related articles on the PHP Chinese website!