<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SSH &#8211; 编程技术记录</title>
	<atom:link href="https://blog.z6z8.cn/tag/ssh/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.z6z8.cn</link>
	<description>世界你好!</description>
	<lastBuildDate>Fri, 27 Nov 2020 10:02:24 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.3</generator>
	<item>
		<title>macos 配置 git ssh访问方式</title>
		<link>https://blog.z6z8.cn/2020/11/27/macos-%e9%85%8d%e7%bd%ae-git-ssh%e8%ae%bf%e9%97%ae%e6%96%b9%e5%bc%8f/</link>
		
		<dc:creator><![CDATA[holdsky]]></dc:creator>
		<pubDate>Fri, 27 Nov 2020 10:02:24 +0000</pubDate>
				<category><![CDATA[安全运维]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[SSH]]></category>
		<guid isPermaLink="false">http://blog.z6z8.cn/?p=933</guid>

					<description><![CDATA[生成 ssh key $ ssh-keygen -t rsa -C "git服务端留存的邮箱地址" Gener [&#8230;]]]></description>
										<content:encoded><![CDATA[<h2>生成 ssh key</h2>
<pre><code class="language-shell">$ ssh-keygen -t rsa -C "git服务端留存的邮箱地址" 

Generating public/private rsa key pair.
Enter file in which to save the key (~/.ssh/id_rsa): "这里输入ssh key保存路径，不建议使用默认地址"
Enter passphrase (empty for no passphrase): "这里输入密码，建议输入空（方便后续配置）"
Enter same passphrase again: "再输入一遍密码,建议输入空（方便后续配置）"</code></pre>
<p>应生成两个文件，公钥和私钥，文件名形式为<code>xxx</code>(私钥)，<code>xxx_pub</code>或者<code>xxx.pub</code>(公钥)。记住ssh key生成的文件路径。</p>
<blockquote>
<p>默认情况下，ssh会使用<code>~/.ssh/id_rsa</code>这个私钥，但无法处理访问多个ssh远端的场景。</p>
</blockquote>
<h2>配置本地ssh访问git使用的私钥</h2>
<p>打开 <code>~/.ssh/config</code>文件，如果没有则创建一个文本文件，添加如下内容</p>
<pre><code class="language-shell"># 请保证 Host 和 HostName 的值相同 （macos11 实测不相同时，git ssh 访问失败）

# 远端ssh主机别名
Host bitbucket.cmbc.com.cn
    # 远端ssh主机名（域名或者ip都可以）
    HostName bitbucket.cmbc.com.cn
    # 鉴权文件 ，这填写ssh私钥文件路径
    IdentityFile "ssh 私钥文件路径"
    # 使用公钥算法进行鉴权
    PreferredAuthentications publickey</code></pre>
<p>关于 ssh config 更多细节参考 <a href="https://linux.die.net/man/5/ssh_config">https://linux.die.net/man/5/ssh_config</a></p>
<h2>配置git上的鉴权公钥</h2>
<p>不同的git服务方式不一样，以bitbucket为例：<br />
登录bitbucket，依次点击头像 -&gt; Manage account  -&gt; SSH keys -&gt; Add key ，</p>
<p>将ssh 公钥文件内容复制到在输入框中，然后 保存(点击 &quot;Add key&quot; 按钮)</p>
<blockquote>
<p>ssh 公钥形式通常是ssh-rsa  + base64编码的公钥 + 邮箱地址</p>
</blockquote>
<h2>配置本地已有git仓库的访问协议</h2>
<pre><code class="language-shell"># 查询远程仓库地址
git remote -v

# 添加ssh协议  地址需要访问网页版的bitbucket仓库获取
git remote set-url --add origin ssh://git@bitbucket.cmbc.com.cn:7999/xxx/xxx.git

# 删除http协议 地址由git remote -v获得
git remote set-url --delete origin http://usernamge@bitbucket.cmbc.com.cn:7999/scm/xxx/xxx.git </code></pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>【转】ssh访问控制，多次失败登录即封掉IP，防止暴力破解</title>
		<link>https://blog.z6z8.cn/2020/06/27/%e3%80%90%e8%bd%ac%e3%80%91ssh%e8%ae%bf%e9%97%ae%e6%8e%a7%e5%88%b6%ef%bc%8c%e5%a4%9a%e6%ac%a1%e5%a4%b1%e8%b4%a5%e7%99%bb%e5%bd%95%e5%8d%b3%e5%b0%81%e6%8e%89ip%ef%bc%8c%e9%98%b2%e6%ad%a2%e6%9a%b4/</link>
		
		<dc:creator><![CDATA[holdsky]]></dc:creator>
		<pubDate>Sat, 27 Jun 2020 00:29:20 +0000</pubDate>
				<category><![CDATA[学习笔记]]></category>
		<category><![CDATA[安全运维]]></category>
		<category><![CDATA[SSH]]></category>
		<guid isPermaLink="false">http://blog.z6z8.cn/?p=872</guid>

					<description><![CDATA[读取/var/log/secure，查找关键字 Failed，例如： Sep 17 09:08:09 loca [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>读取/var/log/secure，查找关键字 Failed，例如：</p>
<p>Sep 17 09:08:09 localhost sshd[29087]: Failed password for root from 13.7.3.6 port 44367 ssh2<br />
Sep 17 09:08:20 localhost sshd[29087]: Failed password for root from 13.7.3.6 port 44367 ssh2<br />
Sep 17 09:10:02 localhost sshd[29223]: Failed password for root from 13.7.3.6 port 56482 ssh2<br />
Sep 17 09:10:14 localhost sshd[29223]: Failed password for root from 13.7.3.6 port 56482 ssh2</p>
<p>从这些行中提取IP地址，如果次数达到10次(脚本中判断次数字符长度是否大于1)则将该IP写到 <code>/etc/hosts.deny</code>中。</p>
<p>步骤：</p>
<p>1、先把始终允许的IP填入 /etc/hosts.allow ，这很重要！比如：<br />
sshd:19.16.18.1:allow<br />
sshd:19.16.18.2:allow</p>
<p>2、脚本 /usr/local/bin/secure_ssh.sh</p>
<pre><code class="language-bash">#! /bin/bash
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' &gt; /usr/local/bin/black.list
for i in &lt;code&gt;cat  /usr/local/bin/black.list&lt;/code&gt;
do
  IP=&lt;code&gt;echo $i |awk -F= &#039;{print $1}&#039;&lt;/code&gt;
  NUM=&lt;code&gt;echo $i|awk -F= &#039;{print $2}&#039;&lt;/code&gt;
  if [ ${#NUM} -gt 1 ]; then
    grep $IP /etc/hosts.deny &gt; /dev/null
    if [ $? -gt 0 ];then
      echo "sshd:$IP:deny" &gt;&gt; /etc/hosts.deny
    fi
  fi
done</code></pre>
<p>3、将secure_ssh.sh脚本放入cron计划任务，每1分钟执行一次。</p>
<h1>crontab -e</h1>
<p><em>/1 </em> <em> </em> *  sh /usr/local/bin/secure_ssh.sh</p>
<p>原文：<a href="https://www.cnblogs.com/panblack/p/secure_ssh_auto_block.html">https://www.cnblogs.com/panblack/p/secure_ssh_auto_block.html</a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Windows10：配置Visual Studio Code 以SSH方式访问远程主机</title>
		<link>https://blog.z6z8.cn/2019/09/21/windows10%ef%bc%9a%e9%85%8d%e7%bd%aevisual-studio-code-%e4%bb%a5ssh%e6%96%b9%e5%bc%8f%e8%ae%bf%e9%97%ae%e8%bf%9c%e7%a8%8b%e4%b8%bb%e6%9c%ba/</link>
		
		<dc:creator><![CDATA[holdsky]]></dc:creator>
		<pubDate>Sat, 21 Sep 2019 02:49:16 +0000</pubDate>
				<category><![CDATA[安全运维]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Visual Studio Code]]></category>
		<category><![CDATA[Windows]]></category>
		<guid isPermaLink="false">http://139.155.43.7:8000/?p=348</guid>

					<description><![CDATA[Windows10上遇到过ssh的坑，记录下过程 参考 https://code.visualstudio.c [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Windows10上遇到过ssh的坑，记录下过程</p>
<p>参考 <a href="https://code.visualstudio.com/docs/remote/troubleshooting#_installing-a-supported-ssh-client">https://code.visualstudio.com/docs/remote/troubleshooting#_installing-a-supported-ssh-client</a></p>
<h1>环境和知识准备</h1>
<ul>
<li>远程主机，并开启ssh-server服务（通常端口22）</li>
<li>Windows环境（本文Windwos10家庭版）</li>
<li>Visual Studio Code</li>
<li>公钥加密算法，对SSH，通常为RSA</li>
<li>已经生成好的ssh公钥文件和私有文件</li>
</ul>
<h1>步骤</h1>
<h2>安装ssh-client</h2>
<p>对于Windows10的一些版本，可以通过<code>设置--系统--应用和功能--管理可选功能--添加功能</code>来开启ssh-client，奈何本穷的Windows10不支持。</p>
<p>还有两种方法来安装ssh-client</p>
<p>通过PowerShell安装，以管理员方式启动PowerShell，具体参考<a href="https://docs.microsoft.com/zh-cn/windows-server/administration/openssh/openssh_install_firstuse" title="这里">这里</a>，反正本穷是没有成功。</p>
<p>于是，只有通过安装Git for Windows来安装ssh-client了，<a href="https://git-scm.com/download/win" title="下载地址">下载地址</a></p>
<h2>安装RemoteSSH</h2>
<p>这里需要给Visual Studio Code 安装扩展包，以支持RemoteSSH。<code>Visual Studio Code -- 查看 --扩展</code>,在扩展中搜索<code>Remote Development</code>，然后安装这个扩展包，会自动安装相关依赖包。</p>
<h2>配置Vistual Studio Code SSH</h2>
<p><code>Visual Studio Code -- 设置</code>，搜索SSH，在结果列表中找到<code>扩展--Remote-SSH -- Remote.SSH:Config File</code>，自定义RemoteSSH的配置文件路径，然后创建这个配置文件，内容如下:</p>
<pre><code>Host 自定义别名
    User 远程主机ssh登陆的用户名
    HostName 远程主机名字，可以是ip地址
    Port 远程主机ssh端口号，一般是22
    IdentityFile 身份验证文件路径，即ssh私钥文件路径</code></pre>
<h2>访问</h2>
<p>Vistual Studio Code -- 查看 --命令面板 --Remote-SSH：Connect ToHost</p>
<p>选择配置文件中配置好的主机即可。</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
