SSH免密码登录Linux服务器
来源:互联网 发布:软件找不到怎么卸载 编辑:程序博客网 时间:2024/05/20 05:08
服务器:Ubuntu 16.04 x64
本机:Ubuntu 16.04 x64
1、查看本机是否存在密钥对
username@ubuntu:~$ cd ~/.sshusername@ubuntu:~/.ssh$ lsid_rsa id_rsa.pub
username@ubuntu:~$ ssh-keygen -t rsaGenerating 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@ubuntuThe 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)? yesWarning: Permanently added 'romote_server_IP' (ECDSA) to the list of known hosts.root@romote_server_IP's password: xxxxxxxxxxid_rsa.pub 100% 390 0.4KB/s 00:00 username@ubuntu:~$
4、登录远程服务器,将本机公钥添加到远程服务器的authorized_keys中,如果服务器中用户目录下不存在.ssh文件夹和authorized_keys文件,则新建并修改权限
username@ubuntu:~$ ssh root@romote_server_IProot@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/advantagexx packages can be updated.xx updates are security updates.Last login: last_login_time from xxx.xx.xx.xxxroot@remote_server:~# ls -a. .bash_history .cache .viminfo id_rsa.pub.. .bashrc .profile .wget-hsts root@remote_server:~# mkdir .sshroot@remote_server:~# chmod 700 ~/.sshroot@remote_server:~# touch ~/.ssh/authorized_keysroot@remote_server:~# chmod 600 ~/.ssh/authorized_keysroot@remote_server:~# cat ~/id_rsa.pub >> ~/.ssh/authorized_keysroot@remote_server:~#
5、本机配置远程服务器别名代替IP地址
username@ubuntu:~$ vim ~/.ssh/configHost remote_server_aliasHostName xxx.xxx.xx.xxPort 22User remote_server_usernamePreferredAuthentications publickeyIdentityFile ~/.ssh/id_rsa~ ~ :wqusername@ubuntu:~$ ssh remote_server_aliasWelcome 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/advantagexx packages can be updated.xx updates are security updates.Last login: last_login_time from xxx.xx.xx.xxxroot@remote_server:~#
阅读全文
0 0
- SSH免密码登录Linux服务器
- linux指令 ssh 免密码登录服务器
- 【linux】SSH免密码登录
- linux ssh 免密码登录
- linux ssh免密码登录
- Linux SSH免密码登录
- Linux SSH免密码登录
- Linux SSH 免密码登录
- linux ssh 免密码登录
- linux:ssh免密码登录
- Linux SSH 免密码登录
- ssh 免密码登录linux
- Linux ssh 免密码登录
- Linux ssh免密码登录
- Linux:SSH免密码登录
- Linux ssh免密码登录
- Linux ssh免密码登录
- Linux-----SSH免密码登录
- Digital Ocean优惠码
- [LeetCode]1. Two Sum
- break goto return continue
- UE4虚幻引擎结构
- java设计模式--Singleton单例模式
- SSH免密码登录Linux服务器
- 51Nod——1004 n^n的末位数字
- 1.系统管理命令ps和kill
- 000-动态规划简介
- Java volatile变量原子性讨论
- Codevs 1217 && 洛谷 P1083 借教室
- Python 进程,获取进程id( os.getpid() )
- 静态内部类的加载
- [jQuery] 把jqGrid修改为响应式表格