1.添加用户
useradd -d /home/sunjianhua sunjianhua
2.生成密钥
su -sunjianhua
cd /home/sunjianhua
ssh-keygen -t rsa -b 2048
cd .ssh
cat id_rsa.pub > authorized_keys
mkdir sunjianhua
mv id_rsa* ./sunjianhua
tar -zcvf sunjianhua.tar.gz sunjianhua
sz sunjianhua.tar.gz
rm -rf sunjianhua*
su root
chmod 600 authorized_keys
3.设置ssh并登录
# vim /etc/ssh/sshd_config
在文件中变更一下内容:
Port 12345
UseDNS no
AddressFamily inet
PermitRootLogin no
SyslogFacility AUTHPRIV
PasswordAuthentication no
AllowUsers sunjianhua
# 重启sshd服务
service sshd restart
然后登陆: sunjianhua/刚才下载的私钥
注:如果登录不了,需要在防火墙里面配置12345端口
4.免密登录到目标服务器
将你的公钥填充到一个远程机器上的authorized_keys文件中!
ssh-copy-id -i ~/.ssh/id_rsa.pub user@machine
5.设置多个免密登录配置
# vim .ssh/config
Host test1
HostName 149.129.167.111
Port 22
User root
IdentitiesOnly yes
Host test2
HostName 149.129.172.222
Port 22
User root
IdentitiesOnly yes
Host test3
HostName 47.241.118.333
Port 8888
User root
IdentitiesOnly yes
配置git多个key
Host host1HostName www.host2.com IdentityFile C:\Users\username\.ssh\id_rsa PreferredAuthentications publickey User userName
Host host2
HostName www.host2.com IdentityFile C:\Users\username\.ssh\id_rsa PreferredAuthentications publickey User userName
Host host3
HostName www.host3.com IdentityFile C:\Users\username\.ssh\id_rsa_company PreferredAuthentications publickey User userName
版权属于:sunjianhua
本文链接:https://sunjianhua.cn/archives/centos-ssh-login.html
转载时须注明出处及本声明,如果不小心侵犯了您的权益,请联系邮箱:NTA2MTkzNjQ1QHFxLmNvbQ==