目录 start
目录 end |2018-04-17| 码云 | CSDN | OSChina
Linux启动或禁止SSH用户及IP的登录 ssh和ssh2之间的免密码登陆详解 SSH原理与运用(一):远程登录 SSH原理与运用(二):远程操作与端口转发
ssh user@host 默认22端口登录系统ssh -p port user@host 指定端口登录ssh -T user@host 测试能否登录上
ssh -i 私钥绝对路径 user@host采用指定私钥登录(一般默认是.ssh/id_rsa)私钥一定要是 600 权限 去除私钥的口令
openssl rsa -in ~/.ssh/id_rsa -out ~/.ssh/id_rsa_new在GitForWindows里面虽然有openssl,但是这个命令却执行不了
使用密码方式免去密码登录(因为一些奇怪的需求, 又想省事)
ssh登录然后执行一系列命令, sudo会执行不了 需要加 -t 参数才行
客户端安装软件
sudo spt-get install openssh-clientssh-keygen 可以设置密码,为了方便也可以全部采用默认服务端安装软件
sudo apt-get install openssh-serversudo /etc/init.d/ssh start 或者 service ssh start/etc/ssh/sshd_configps -e |grep ssh/etc/init.d/ssh stop客户端
gedit id_rsa.pub 然后复制该公钥内容
cat ~/.ssh/id_rsa.pub | xclip -sel clip 将文件复制到剪贴板cat ~/.ssh/id_rsa.pub | xsel -b 也是文件复制到剪贴板服务器端
sudo vim authorized_keys 粘贴客户端公钥内容sudo chmod 600 authorized_keys 确保 其 group和other位没有 w 权限两方安装好软件 客户端生成好了秘钥对之后
默认端口:ssh-copy-id "username@host" 输密码就可以了
指定端口 ssh-copy-id ”-p port username@host“
ssh-copy-id " username@host" -p port成功后 客户端登录 ssh -p 22 username@ip
/etc/ssh/sshd_confg 文件中PermitRootLogin no 改为yes 重新启动ssh服务。注意:
ssh-keygen -f "../../../../home/kcp/.ssh/known_hosts" -R 120.78.154.52ssh_exchange_identification: Connection closed by remote host 错误: echo "PermitRootLogin without-password" >> /etc/ssh/sshd_config ;\
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config ;\
echo "sshd: ALL" >> /etc/hosts.allow && service sshd restart这是什么问题,这么6的么, 配置好了公钥
$ ssh -p 8888 git@184.170.220.117
The authenticity of host '[184.170.220.117]:8888 ([184.170.220.117]:8888)' can't be established.
ECDSA key fingerprint is SHA256:Ha9k9dsMxtTaDgN4maUy1VoNzzsm+uMb84zcib6U5jU.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[184.170.220.117]:8888' (ECDSA) to the list of known hosts.
PTY allocation request failed on channel 0
Welcome to GitLab, Carlsiry Chen!
Connection to 184.170.220.117 closed.
emmm.出现这样的输出竟然是连接上了,,,
vim ~/.ssh/config
Host aliyun
HostName www.ttlsa.com
Port 22
User root
IdentityFile ~/.ssh/id_rsa.pub
IdentitiesOnly yes
参数解释
HostName 指定登录的主机名或IP地址
Port 指定登录的端口号
User 登录用户名
IdentityFile 登录的公/私钥文件 奇怪的是有时候用公有时候用私??
IdentitiesOnly 只接受SSH key 登录
PubkeyAuthentication
ssh aliyun 即可登录 但是要输入生成公钥时的密码, 方便多公钥的情况
修改欢迎信息 /etc/motd
ssh-keygen 生成SSH密钥对
ssh-add 私钥文件绝对路径
ssh-agent bash 对应自己的解释器环境git@git.:Rusher/helloworldgit remote set-url origin git@rusher_gitlab:Rusher/helloworldgit remote set-url origin git@root_gitlab:root/helloworld config Host default
HostName github.com
User git
IdentityFile ~/.ssh/default_id_rsa.pub
ssh -T git@default在/etc/ssh/sshd_config添加以下信息,然后重启ssh服务
X11Forwarding yes
X11DisplayOffset 10
ssh -X -p port user@host 登录即可
ssh user@host 'cmd \
&& cmd \'