SSH免密码登录Linux服务器
2017-10-14 17:42
537 查看
服务器:Ubuntu 16.04 x64
本机:Ubuntu 16.04 x64
1、查看本机是否存在密钥对
2、如果不存在,则首先生成密钥对
3、将本机公钥上传到远程服务器
4、登录远程服务器,将本机公钥添加到远程服务器的authorized_keys中,如果服务器中用户目录下不存在.ssh文件夹和authorized_keys文件,则新建并修改权限
5、本机配置远程服务器别名代替IP地址
本机:Ubuntu 16.04 x64
1、查看本机是否存在密钥对
username@ubuntu:~$ cd ~/.ssh username@ubuntu:~/.ssh$ ls id_rsa id_rsa.pub
2、如果不存在,则首先生成密钥对
username@ubuntu:~$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/username/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/username/.ssh/id_rsa. Your public key has been saved in /home/username/.ssh/id_rsa.pub. The key fingerprint is: SHA256:xxxxxxxxxxxxxxxxxxxx username@ubuntu The key's randomart image is: +---[RSA 2048]----+ | | | | | | | A | | randomart | | image | | | | | | | +----[SHA256]-----+
3、将本机公钥上传到远程服务器
username@ubuntu:~$ scp ~/.ssh/id_rsa.pub root@romote_server_IP:/root/ The authenticity of host 'romote_server_IP (romote_server_IP)' can't be established. ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'romote_server_IP' (ECDSA) to the list of known hosts. root@romote_server_IP's password: xxxxxxxxxx id_rsa.pub 100% 390 0.4KB/s 00:00 username@ubuntu:~$
4、登录远程服务器,将本机公钥添加到远程服务器的authorized_keys中,如果服务器中用户目录下不存在.ssh文件夹和authorized_keys文件,则新建并修改权限
username@ubuntu:~$ ssh root@romote_server_IP root@romote_server_IP's password: Welcome to Ubuntu 16.04.x LTS (GNU/Linux x.x.x-xx-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage xx packages can be updated. xx updates are security updates. Last login: last_login_time from xxx.xx.xx.xxx root@remote_server:~# ls -a . .bash_history .cache .viminfo id_rsa.pub .. .bashrc .profile .wget-hsts root@remote_server:~# mkdir .ssh root@remote_server:~# chmod 700 ~/.ssh root@remote_server:~# touch ~/.ssh/authorized_keys root@remote_server:~# chmod 600 ~/.ssh/authorized_keys root@remote_server:~# cat ~/id_rsa.pub >> ~/.ssh/authorized_keys root@remote_server:~#
5、本机配置远程服务器别名代替IP地址
username@ubuntu:~$ vim ~/.ssh/config Host remote_server_alias HostName xxx.xxx.xx.xx Port 22 User remote_server_username PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa ~ ~ :wq username@ubuntu:~$ ssh remote_server_alias Welcome to Ubuntu 16.04.x LTS (GNU/Linux x.x.x-xx-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage xx packages can be updated. xx updates are security updates. Last login: last_login_time from xxx.xx.xx.xxx root@remote_server:~#
相关文章推荐
- Xshell5配置ssh免密码登录-公钥与私钥登录linux服务器(xshell如何登陆上阿里云服务器)
- 设置ssh通过密钥免密码登录Linux服务器
- ssh不使用密码登录Linux服务器
- python批量操作Linux服务器脚本,ssh密码登录(执行命令、上传、下载)(一)
- Xshell5配置ssh免密码登录-公钥与私钥登录linux服务器(xshell如何登陆上阿里云服务器)
- linux操作系统-两台linux服务器SSH免密码登录
- windows下crywin SSH免密码登录到远程linux服务器详解
- ssh无需密码登录linux服务器
- 内网ssh登录linux服务器过程中密码验证很慢的解决办法
- python批量操作Linux服务器脚本,ssh密码登录(执行命令、上传、下载)(一)
- SSH免密码登录Linux服务器
- 【原创】Linux服务器集群通过SSH无密码登录
- ssh免密码(秘钥)登录Linux服务器
- mac 脚本ssh自动密码登录服务器,非公钥
- MAC便捷ssh直接登录远程服务器(免输密码)
- 使用ssh-keygen和ssh-copy-id三步实现SSH无密码登录
- SSH无需密码密钥登录
- Mac 下配置 SSH 免密码安全登录
- redhat ssh 免密码登录设置后还是提示需要输入密码
- ssh 免密码登录