In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How can I log in to the linux server without a password by setting ssh? I believe that many inexperienced people are at a loss about this, so this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Rsa authentication login method
Make a key pair
Enter the following command under the client (local machine) terminal
Ssh-keygen-t [rsa | dsa]
Rsa and dsa represent different algorithms
For example:
Ssh-keygen-t rsa
Just enter all the time (no need to set the password)
A key file and a private key file id_rsa,id_rsa.pub will be generated (or id_dsa,id_dsa.pub if dsa is used)
The build location is under the / root/.ssh/ folder (I am using the root user, so under root, the generation process will prompt for the location of the file)
.ssh is a hidden folder to view using ls-a
Place the public key at the location specified by the server
Method 1. Copy directly
1. Copy the public key to the .ssh folder under the root user of the server (under the .ssh folder under the user who logs in)
Scp / root/.ssh/id_rsa.pub root@172.16.0.164:/root/.ssh/
2. Install the public key
Log in to the server cd / root/.ssh/
Cat id_rsa.pub > > authorized_keys
Method 2. Use ssh-copy-id command to copy (recommended)
An order goes directly to ok.
Ssh-copy-id root@172.16.0.164
Verification
If you don't have to enter a password, you will succeed, otherwise you will fail.
Ssh root@172.16.0.164
Matters needing attention
The above operation has been tested and there is no problem.
There will be differences between the version of linux and the users used.
If there is a problem, you can consider the following two points
1. File permissions of id_rsa.pub and authorized_keys
Chmod 600 authorized_keyschmod 700 ~ / .ssh
2. Configuration file of ssh
Vim / etc/ssh/sshd_config # enables RSA authentication, defaults to yes RSAAuthentication yes to enable public key authentication, and defaults to yes PubkeyAuthentication yes # root user ssh login PermitRootLogin yes
(I haven't modified any of these configurations. Mine is redhat7.2.)
Customize and write a simple shell script
Create a file under the commonly used folder
Touch 164.sh
Edit a file
File content ssh root@172.16.0.164
Vim 164.sh # add content ssh root@172.16.0.164 save exit: wq
Increase the execution rights of users
Chmod upright x 164.sh
It's better to use the tab key.
. / 164.sh
Expect command secret-free login method
You may feel the need to operate the server system is not good, of course, you can only operate locally.
You only need to operate locally to use the expect command, provided you have the command expect locally.
1. Create a file
Touch expectssh.sh
Add the following to change the user, ip, and password to your own
#! / usr/bin/expect-f set username root set hostname 172.16.0.164 set password 123456 spawn ssh $username@$hostname set timeout 1 expect {"yes/no" {send "yes\ r"; exp_continue}} expect "$username@$hostname's password:" send "$password\ r" interact
2. Add expectssh.sh execution permission
Chmod upright x expectssh.sh
3. Execute orders
Expect expectssh.sh, after reading the above, have you mastered how to log in to the linux server without a password by setting ssh? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
Yum install-y sysstatsar-n DEV 1watch-n 1 "ifconfig enp0s8"
© 2024 shulou.com SLNews company. All rights reserved.